Mappedby Properties for JPA Onetoone,onetomany and Manytomany

Source: Internet
Author: User

Of the four associations Onetoone,onetomany,manytoone and Manytomany, only Onetoone, Onetomany, and Manytomany have mappedby attributes in relation to each other.
The following is an explanation of the Mappedby attribute in the Java doc:
The field that owns the relationship. Required unless the relationship is unidirectional.
Translated into Chinese is:
Domains that have association relationships are not required if the relationship is one-way.
So what does it mean to have an association, so to say that the assumption is one-to-one, then the party that owns the relationship has the ability to establish, release, and update the relationship with the other, and the other side has no, only passive management; in two-way, multi-and bidirectional many-to-many is a meaning.
Since jointable and joincolumn are generally defined at the end of the owning relationship, and Hibernate does not allow Mappedby to be defined with jointable and Joincolumn, Mappedby must be defined in the owning party of the relationship, The owned side, which is a party that defines jointable and Joincolumn mutexes, points to a field in the owning party about the owning party, possibly an object (Onetomany), or a collection of objects (Manytomany).
The owner of the relationship is responsible for maintaining the relationship, establishing a foreign key in the relationship owner, so both jointable and joincolumn are defined in the relationship owner.
Another feature of Mappedby is that after adding this attribute, you can avoid automatically generating intermediate tables.
Finally, mappedby= "xxx", so to understand, Mappedby defined in the relationship of the owner, the mappedby definition of the class (either a single or a collection form) on the relationship owner of the name of the party is "xxx".

Mappedby Properties for JPA Onetoone,onetomany and Manytomany

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.