我有MySQL database
这个结构的表:
和这里的对象的休眠映射PatientDAO
:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cz.cvut.fit.genepi.models.PatientDAO" table="patient">
<id name="_id" type="int">
<column name="id" precision="6" scale="0" not-null="true" />
<generator class="assigned" />
</id>
<property name="_nin" type="long">
<column name="nin" length="20" not-null="false" />
</property>
<property name="_birthday" type="date">
<column name="birthday" length="7" not-null="true" />
</property>
<property name="_gender" type="string">
<column name="gender" length="10" not-null="true" />
</property>
<property name="_doctor_id" type="int">
<column name="doctor_id" precision="6" scale="0" not-null="false" />
</property>
<property name="_deleted" type="int">
<column name="deleted" precision="1" scale="0" not-null="false" />
</property>
<property name="_checked" type="int">
<column name="checked" precision="1" scale="0" not-null="false" />
</property>
<property name="_contact_id" type="int">
<column name="contact_id" precision="6" scale="0" not-null="false" />
</property>
<property name="_comment_id" type="int">
<column name="comment_id" precision="6" scale="0" not-null="false" />
</property>
</class>
</hibernate-mapping>
但是当我试图从 dtb 获取一些样本数据并将它们打印出来时,我只得到0
. 这发生在 的任何可能属性上Patient DAO
。对于任何id
被搜索的患者。我敢肯定,那个病人id==0
就在那个表里。
findByID
功能:
public T findByID(Class<T> myClass, int id) {
Session hibernateSession = this.getSession();
T t = null;
t = (T) hibernateSession.get(myClass, id);
return t;
}
一部分PatientDAO
(没有setter和getter):
public class PatientDAO implements java.io.Serializable {
/**
* generated serialVersionUID
*/
private static final long serialVersionUID = -8172690860460945951L;
private int _id;
private long _nin;
private Date _birthday;
private String _gender;
private int _doctor_id;
private int _deleted;
private int _checked;
public int get_checked() {
return _checked;
}
}
我个人的建议是,我的映射出现了问题,因为对于更简单的对象,它运行良好。但是我对 很陌生hibernate
,所以我不知道有什么问题。如果有人可以提供帮助,我会非常高兴。