hibernate之一对一

 2023-09-19 阅读 22 评论 0

摘要:一对一实际上是特殊的多对一,只是将那个多变成了唯一,我这里写的一对一配置,采用的是相同字段的主键的一对一,一个表的主键可以引用另一表的主键作为自己的主键 表一: <?xml version="1.0"?> <!DOCTYPE hibernate-m

一对一实际上是特殊的多对一,只是将那个多变成了唯一,我这里写的一对一配置,采用的是相同字段的主键的一对一,一个表的主键可以引用另一表的主键作为自己的主键

表一:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="com.newtouch.entity" auto-import = "true"><class name="Account" table="account" ><id name="userid" ><generator class="foreign"><param name="property">signon</param></generator></id><one-to-one name="signon" class="Signon" constrained="true"></one-to-one></class></hibernate-mapping>

hibernate5和4的区别?表二:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.newtouch.entity" ><class name="Signon" table="signon" ><id name="username"><generator class="assigned"/></id><one-to-one name="account" class="Account"></one-to-one></class></hibernate-mapping>

明显account引用了signon的主键,所以,在插入数据时把signon  给set进account即可

 

hibernate和spring、转载于:https://www.cnblogs.com/ShaoXin/p/7261445.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/79253.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息