2017-04-25 54 views
0

`我可以在hibernate映射文件中使用2個主鍵ID嗎?

<hibernate-mapping> 

<class name="beans.EmployeeBean" table="employeedetails" schema="Employee"> 
<id name="empId" column="empid"/> 
<id name="employeeusername" column="username"/> 
<property name="firstname" column="firstname"/> 
<property name="designation" column="designation"/> 
<property name="email" column="email"/> 
<property name="role" column="role"/> 
</class> 

</hibernate-mapping> 

在當我把第二個ID的用戶名我得到錯誤,在我的數據庫也在1臺這個代碼,我把2列作爲主鍵。

+0

你嘗試答案這裏建議:http://stackoverflow.com/questions/27642101/how-do-i-create -a-複合主鍵合冬眠-內最HBM-XML的文件 –

回答

0

你不能,但你可以做出獨特的屬性:

<property name="employeeusername" column="username" not-null="true" unique="true"/> 
相關問題