public class ProfilePic implements java.io.Serializable {
private String picId;
private String profilePicPath;
private String smallPicPath;
private String adddate;
private Integer aid;
//getter and setter
}
public class Atom implements java.io.Serializable {
private Integer id;
private String name;
//getter and setter
}
Atom.hbm.xml
<hibernate-mapping>
<class name="test.Atom" table="atom" catalog="xrcwrn_sms">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity"></generator>
</id>
<property name="name" type="string">
<column name="name" length="200" unique="true" />
</property>
</class>
</hibernate-mapping>
ProfilePic.hbm.xml
<hibernate-mapping>
<class name="test.ProfilePic" table="profile_pic" catalog="xrcwrn_sms">
<id name="picId" type="string">
<column name="pic_id" length="200" />
<generator class="assigned" />
</id>
<property name="profilePicPath" type="string">
<column name="profile_pic_path" length="1000" />
</property>
<property name="smallPicPath" type="string">
<column name="small_pic_path" length="1000" />
</property>
<property name="adddate" type="string">
<column name="adddate" length="100" />
</property>
<property name="aid" type="java.lang.Integer">
<column name="aid" />
</property>
</class>
</hibernate-mapping>
我想从ProfilePic
只获取一行。
Atom
和ProfilePic
具有一对多映射(一个原子可以有多个profilePic)
如何映射。
答案 0 :(得分:0)
您尚未在hbm.xml
个文件中定义关系。请进行以下更改
<hibernate-mapping>
<class name="test.Atom" table="atom" catalog="xrcwrn_sms">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity"></generator>
</id>
<property name="name" type="string">
<column name="name" length="200" unique="true" />
</property>
<set name="profilePics" table="profile_pic" inverse="true" lazy="true" fetch="select">
<key>
<column name="aid" not-null="true" />
</key>
<one-to-many class="test.ProfilePic" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="test.ProfilePic" table="profile_pic" catalog="xrcwrn_sms">
<id name="picId" type="string">
<column name="pic_id" length="200" />
<generator class="assigned" />
</id>
<many-to-one name="atom" class="test.Atom" fetch="select">
<column name="aid" />
</many-to-one>
<property name="profilePicPath" type="string">
<column name="profile_pic_path" length="1000" />
</property>
<property name="smallPicPath" type="string">
<column name="small_pic_path" length="1000" />
</property>
<property name="adddate" type="string">
<column name="adddate" length="100" />
</property>
</class>
</hibernate-mapping>
还需要更改.java
个文件
public class Atom implements java.io.Serializable {
private Integer id;
private String name;
private Set profilePics = new HashSet(0);
//constructor, getter and setter
}
public class ProfilePic implements java.io.Serializable {
private String picId;
private String profilePicPath;
private String smallPicPath;
private String adddate;
private Atom atom;
//constructor, getter and setter
}
您需要分享有关您的问题fetch one row from ProfilePic
的更多信息。对我来说不是很清楚。