mappedBy和inverse属性是相同的? [英] mappedBy and inverse attributes are same?

查看:119
本文介绍了mappedBy和inverse属性是相同的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的没有得到mappedBy属性的意义。请告诉我,如果我们不使用它,效果如何。如果你能举出一个对我来说很好的例子。



另外,mappedBy和inverse属性是一样的吗?

是的,通过注释映射执行的功能与XML文件中的相反。



2个实体参与其中。



在一对一或一对多或多对一的情况下,密钥将存储在其中一个实体中。将它存储在两个地方没有任何意义。



它必不可少的告诉hibernate,关键在于关系的另一端。



因此,如果存在具有一对一关系的实体A和B,并且您在A中看到mappedBy属性,则外键(指向A)存储在B中。


I really did not get the meaning of the mappedBy attribute. Please tell me how it will effect if we not use it. If you can give the example that will be great for me.

Also, the attribute mappedBy and inverse aree the same?

解决方案

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.

这篇关于mappedBy和inverse属性是相同的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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