我在MySQL database
中有这个结构的表:
并在此处对对象PatientDAO
进行hibernate 映射:
<?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
还很陌生,所以我无法弄明白,可能出现什么问题......如果有人可以提供帮助,我会很高兴。
答案 0 :(得分:0)
问题出现在糟糕的映射中......我实际上已经知道了,nin应该是varchar
并且我将其声明为long