如何解决使用一对一映射在一张表中休眠外键和主键
我是冬眠的初学者,只是有一个疑问, 你能帮我设计以下关系吗
Employee table
`Eid - primary key`
`ename`
`esal`
Address
`aid` - primary key
addressLine1
city
state
eid - foreign key of employee table
是一对一的关系,员工只有一个地址。
如何在 hibernate 中使用一对一映射管理一张表中的主键和外键。 在休眠中,此关系的 xml 映射可能是什么。
Tried
employee
<class name="Employee" table="employee" schema="system">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="name" column="ename" />
<property name="designation" column="designation" />
<one-to-one name="address" class="Address" cascade="all"/>
</class>
Address
<class name="Address" table="address_details" schema="system">
<id name="eid" column="id">
<generator class="increment">
</generator>
</id>
<property name="address" column="address"></property>
<property name="city" column="city"></property>
<property name="state" column="state"></property>
<one-to-one name="emp" class="Employee" column="eid"></one-to-one>
</class>
解决方法
您可以在互联网上找到大量示例。这个特殊的模型甚至在这里展示:https://en.wikibooks.org/wiki/Java_Persistence/OneToOne
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。