【问题标题】:Can I use 2 primary key id in the hibernate mapping file?我可以在休眠映射文件中使用 2 个主键 ID 吗?
【发布时间】:2017-04-25 06:44:19
【问题描述】:

`

<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 列作为主键。

【问题讨论】:

标签: hibernate


【解决方案1】:

你不能,但你可以让一个属性独一无二:

<property name="employeeusername" column="username" not-null="true" unique="true"/>

【讨论】:

    猜你喜欢
    • 2011-07-26
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多