【发布时间】:2015-06-08 06:35:29
【问题描述】:
我有一个像这样的课堂出勤
public class Attendance implements Serializable
{
private Integer id,userId;
private Date date;
private OfficeTime officeTime;
private Set<TimeSlice> timeSlices;
public Attendance()
{
}
}
现在我正在尝试使用休眠映射复合 ID 制作两个主键
<hibernate-mapping>
<class name="Attendance">
<composite-id>
<key-property name="id"><generator class="increment"/></key-property>
<key-property name="date" />
</composite-id>
<property name="userId" />
<set name="timeSlices" cascade="all" >
<key column="attendanceId" />
<one-to-many class="TimeSlice" />
</set>
<many-to-one name="officeTime" class="OfficeTime"
column="office_id" unique="true" not-null="true"
cascade="all" />
</class>
</hibernate-mapping>
当我这样做时,我得到了错误元素类型“key-property”的内容必须匹配“(meta *,column *,type?)”。 如何设置两个主键,一个必须自动递增。在此先感谢。
【问题讨论】:
-
你只能有一个主键。
-
你看过这个
http://stackoverflow.com/questions/21284175/how-to-make-two-column-as-a-primary-key-in-hibernate-annotation-class -
你希望如何拥有两个“第一”元素?
-
我一天只需要一个对象
-
Hari:重点是:一个“主”键(主,是“第一个”元素)是唯一的。您可以基于多个列创建键,但一个表中不能有多个主键。