What's the difference between inverse and cascade in hibernate?

Source: Internet
Author: User

<Setname= "FB"Cascade= "All-delete-orphan"Inverse= "true"Lazy= "false"><Key><columnname= "zb_id"Not-null= "true" /></Key><One-to-manyclass= "Gov.gzgs.djrwtx.bo.PxglFb" /></Set>  
Both of these properties are used in a multiple-or many-to-many relationship.    Inverse, especially for bidirectional relationships, is not needed in a one-way relationship.    Cascade represents whether a cascade operation is performed, inverse represents whether the relationship is maintained by itself.    The possible values for the Cascade:cascade property are all: associated operations, that is, save-update and delete, in all cases. None: Associated operations are not performed in all cases.    This is the default value.    Save-update: The associated operation is performed when Save/update/saveorupdate is executed.  Delete: The associated operation is performed when the delete is executed. All-delete-orphan: When a node becomes an orphan node in the object graph, the node is deleted.    For example, in a one-to-many relationship, student contains multiple book, which becomes an orphan node when a book is deleted in the object relationship. The possible value of the Inverse:inverse property is true or FALSE, and the default is that False:false represents the relationship maintained by the side, and true represents the relationship maintained by the other party.    In a relationship, the relationship can only be maintained by one party, otherwise there will be a problem (troubleshoot), at the same time must be maintained by a party to the relationship, or there will be mutual shirk responsibility, no one. 1, Cascade (Cascade) quoted "Easy to Hibernate": Cascade (Cascade) in the Hibernate mapping relationship, it refers to when the main side of the operation, the associated object (passive side) is synchronous to perform the same operation,  If the host object calls the Save-update or delete method, whether the colleague is save-update or delete the associated object (the passive side).    As I understand it, the main control here refers to the following: for example, there is an address attribute in the user class, the user and address are a one-to-many relationship, and then when User.save (address), the user is the main control side. 2, Inverse (control direction reversal) quoted "in The Meaning of hibernate": in Hibernate semantics, inverse specifies the direction in the association relationship.  In the association relationship, the Inverse=false is the active side, and the active side is responsible for maintaining the association relationship. The associated relationship here, as I understand it, is that in order to maintain the relationship of two entity classes (tables), some of the attributes added, which may be in two entity classes (tables) or in a separate table, depends on the direct correspondence between the two parties: pS: the maintenance here refers to the corresponding update of the correlation relationship when the main control is added and checked. One-to-many: the property is on more than one side. Should be set on one side of the inverse=true, many of the parties set Inverse=false (more than one side can also not set the inverse property, because the default value is False), which indicates that the association is maintained by many Parties.  Cause: The attribute of the association is in a table of many parties, and it is easy to maintain it on many sides when maintaining the correlation relationship. Many-to-many: properties are in separate tables.  On either side of the inverse=true, the other side inverse=false; Cause: If two is set to true, the two sides have the same maintenance on the relational table (independent table), in fact, as long as one side maintenance on the line, in terms of efficiency, so the setting is reasonable.  One: In fact, a pair of more than a special case, inverse's settings are the same, mainly to see the relationship between the attributes of the party, the side of the Inverse=false. Many to one: that is, a pair of many in turn, no difference.

   Lazy is the meaning of delay, if lazy=true, then that is, the database associated with the child table information will not be loaded when the Hibernate container starts, but when you actually access to the non-identity field of the Word table, will be loaded.
Conversely, if lazy=false, that is, the child table information is loaded simultaneously with the main table information.
General use only when the child table information is fully used, it will be lazy=false

Not-null= "true", which indicates that the property zb_id is not allowed to be empty

What's the difference between inverse and cascade in hibernate?

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.