Hibernate Inverse properties and Cascade properties

Source: Internet
Author: User

Understand:

The inverse property is the end of false. Have the right to manage relationship maintenance

The Cascade attribute refers to the Cascade, said popular point, on the cascade side of the specified operation. Affects the associated object


To give a sample example:

The relationship between class and student is one-to-many

Class class includes ID, name, and set set of students

Student student class includes ID. Name and class ID (foreign key)


Cascade attribute: The student is dependent on the class existence, the class does not exist. So the students don't exist either. In other words, the same time the class is deleted, the student will have to delete it, not vice versa.

When the end of the deletion, the more that the side has no meaning, and many of the end of the deletion, does not mean that the end of a meaningless.

A bit around.

Then the property setting is. Class Sets "All", Student Sets "Save-update", that is. The operation of class can affect student. Save and update after student operation affect class.


Inverse property: This property has administrative and maintenance rights. In a one-to-many relationship, assuming that the class has this right, the class will manage to maintain the student collection. When you save the class. It will update the foreign key attributes in all students ' collections, which is not what we want, when the number is very long and the performance is not good. If you give this right to the student, save the class. Will not update the properties in the student collection, this foreign key can be set manually by ourselves. Popular point is that. Class hypothesis to choose students. The students ' class attributes are changed, and the students ' class attributes are set in turn. Don't worry about the class. The world is pure.


All of these are my personal understanding. The experience on the Web is: theinverse property is usually maintained by a multi-terminal maintenance, many-to-many scenarios. Do not maintain both ends, theCascade property is usually one end set "All", multi-terminal set "save-update".


OK, the world is pure.


Hibernate Inverse properties and Cascade properties

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.