刚学Hibernate,遇到数据插入不全的问题,求大神!

代码:
package com.java.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.junit.Test;

import com.java.bean.Student;

public class StudentTest {
private SessionFactory sessionFactory = null;
private Session session = null;
private Transaction transaction = null;
public void init() {
Configuration config = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
sessionFactory = config.buildSessionFactory(serviceRegistry);
session = sessionFactory.openSession();
transaction = session.beginTransaction();
}
public void destory(){
transaction.commit();
session.close();
sessionFactory.close();
}
@Test
public void getAllPeople(){
init();
Student student = new Student(15,"Tomas",22,"男");
session.save(student);
destory();
}
}

package com.java.bean;

public class Student {
private int id;
private String name;
private int age;
private String sex;
public Student() {
}

public Student(int id, String name, int age, String sex) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age
+ ", sex=" + sex + "]";
}
}
结果id和name进去了,age和sex没有
图片说明
求大神!

查看全部
oliver030
oliver030
2015/07/23 11:01
  • hibernate
  • 点赞
  • 收藏
  • 回答
    私信

8个回复