我上课了
public class Attendance implements Serializable
{
private Integer id,userId;
private Date date;
private OfficeTime officeTime;
private Set<TimeSlice> timeSlices;
public Attendance()
{
}
}
现在我尝试使用hibernate mapping composite-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?)”。 如何设置两个主键,一个必须自动递增。提前谢谢。
答案 0 :(得分:0)
您当前的配置不遵循为composite-id元素设置的架构。 以下是复合ID的架构文档:
<composite-id name="propertyName" class="ClassName" mapped="true|false" access="field|property|ClassName"> node="element-name|." <key-property name="propertyName" type="typename" column="column_name"/> <key-many-to-one name="propertyName class="ClassName" column="column_name"/> ...... </composite-id>
这是一个示例配置:
<composite-id>
<key-many-to-one name="username" class="org.myclass.UserDB" column="user_name"/>
<key-property name="role" type="string" column="role_name"/>
</composite-id>