我对hibernate很新。我的问题是为什么Hibernate没有按照我想要的顺序保存数据。
我想存储数据的方式是..... 姓名,年龄,地址,联系方式
虽然hibernate将其保存为..... 地址,年龄,联系人,姓名
实体
@Entity
public class PersonDetails implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int personId;
private String personName;
private int personAge;
private String personAddress;
private String personContactNumber;
public int getPersonId() {
return personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getPersonName() {
return personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
public int getPersonAge() {
return personAge;
}
public void setPersonAge(int personAge) {
this.personAge = personAge;
}
public String getPersonAddress() {
return personAddress;
}
public void setPersonAddress(String personAddress) {
this.personAddress = personAddress;
}
public String getPersonContactNumber() {
return personContactNumber;
}
public void setPersonContactNumber(String personContactNumber) {
this.personContactNumber = personContactNumber;
}
}
拯救人员Dao实施
public class PersonDatabaseDaoImpl implements PersonDatabaseDao{
private SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
private Session session=sessionFactory.getCurrentSession();
@Override
public void addPerson(PersonDetails person) {
session.beginTransaction();
session.save(person);
session.getTransaction().commit();
}
从人那里获取信息,这是在主
中写的 System.out.print("Enter Name = ");
person.setPersonName(input.next());
System.out.print("\n Enter Age = ");
person.setPersonAge(input.nextInt());
System.out.print("\n Enter Address = ");
person.setPersonAddress(input.next());
System.out.print("\n Enter Contact = ");
person.setPersonContactNumber(input.next());
personData.addPerson(person);