Hibernate'Inverse'在映射文件中 [英] Hibernate 'Inverse' in mapping file

查看:111
本文介绍了Hibernate'Inverse'在映射文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释在XML映射文件中使用inverse,我正在阅读教程,但无法理解其在映射文件中的使用

Can someone explain the use of inverse in the xml mapping file, I am reading the tutorial but failing to understand its use in the mapping file??

谢谢

推荐答案

反向只决定关系中的哪个实体负责更新数据库以反映关联。

Inverse just decides which entity in a relationship is responsible for updating the database for reflecting the association.

假设一对多的双向关联。在代码A和B中有两个类,A包含一组B,B维护一个对A的引用。在数据库级别,只有一个外键要更新,B表包含一列到主键

Assume a one to many bidirectional association. There are two classes in the code A and B, A contains a set of B, B maintains a reference to A. At the database level, there is only one foreign key to be updated, the table for B contains a column to primary key of A.

在这种情况下,假设我们在集合一侧放置inverse = true。这意味着只要向集合添加实体就不会触发外键更新。因为更新外键的可能性由B决定。因此,将A对象添加到A维护的集合不足以更新外键列。 objectA.addToSetOfB(objectB)不会影响外键。

In this case, assume we put the inverse = true on the set side. This implies that just adding an entity to the set will not fire the foreign key update. Because the respnsibility to update the foreign key rests with B. So, adding a B object to the set that A maintains is not enough to update the foreign key column. objectA.addToSetOfB(objectB) will not affect the foreign key.

只有当B给出对A的引用时,才会更新B的表中的外键。所以,objectB.setA(objectA)一定会更新外键,并实际建立关系。

Only when B is given a reference to A, will the foreign key in the table for B be updated. So, objectB.setA(objectA) will surely update the foreign key and actually setup the relationship.

我认为同样的概念将携带到多对多的关系。

I think the same concept will carry to the many to many relationships as well.

这篇关于Hibernate'Inverse'在映射文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆