Hibernate Inverse properties and Cascade properties

Source: Internet
Author: User
Tags set set

Understand:

The end of the inverse property is false, and has the right to manage relationship maintenance

The cascade attribute refers to cascading, that is, the popular point, the action specified at the end of the cascade, affects the associated object


As an example:

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

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

Student Student class contains ID, name and class ID (foreign key)


Cascade attribute: The student is dependent on the class existence, the class does not exist, then the student also does not exist. In other words, when the class is deleted, the student will have to delete it, but 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 set "All", Student set "Save-update", so that the operation of class can affect the student, after the operation of student, save and update only affect class.


Inverse property: This property is a management and maintenance rights, in a one-to-many relationship, if the class has this right, then the class will manage to maintain the student collection, when the class is saved, it will update all students in the collection of foreign key attributes, this is not what we want, when the number of a lot, performance is not good. And if the right to the students, save the class, will not update the properties of the student collection, the foreign key can be manually set by ourselves. The popular point is that if the class chooses the student, then the student's class attribute will be modified, if the student chooses the class, the student's class attribute has been set up, the world is clean without the class to worry about.


These are my personal understanding, the online experience is:Inverse property is generally maintained by a multi-terminal, many-to-many situation to choose one end of maintenance, not both ends are maintained,Cascade property is generally set "all", multi-terminal settings "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.