hibernate中的inverse和mappedBy

本文解释了在Hibernate中inverse和mappedBy的区别与联系。inverse属性用于XML配置中定义关系维护的所有权,而mappedBy则是在注解中使用,两者都用于指定外键的位置。在一个一对一的关系中,mappedBy指明了外键存储在哪一方。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

inverse和mappedBy是同一个东西,只是inverse是用于xml配置,而mappedBy则是用于注解中。


Yes, mapped by in annotations performs the same function as inverse would in XML file.

A relationship always have 2 entities participating in it.

In case of one-one or one-many or many to one, the key will be stored in one of the entites. It does not make any sense to store it in 2 places.

It essential tells hibernate that the key is at the other end of the relationship.

So if there are entities A and B which have a one to one relationship, and you see the mappedBy attribute in A, then the foreign key (which points to A) is stored in B.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值