hibernate cascade operations

Cascading operations

 1. A brief introduction

cascade和inverse (Employee – Department)

l Casade is used to indicate whether a similar operation is performed on the associated slave object when a certain operation is performed on the master object. The commonly used cascade:

         none,all,save-update,delete, lock,refresh,evict,replicate,persist,

         merge, delete-orphan (one-to-many). Generally, cascade is not set for many-to-one and many-to-many, and cascade is set in <one-to-one> and <one-to-many>.

l l   inverse table " Whether to give up maintaining the association relationship " ( the impact on the database table when two objects are associated in Java ), used in the set definition of one-to-many and many-to-many, inverse=” true" indicates that the object does not maintain an association relationship; the value of this property is generally set to false when using an ordered set (note that the default value of hibernate is false).

         One-to-many maintenance of associations is to update foreign keys. Many-to-many maintains an association relationship by adding or removing records in the intermediate table.

         Note: Objects configured as one-to-one do not maintain associations

 

Second, attribute parsing
The lazy attribute of the class element is set to true, which means lazy loading, and if lazy is set to false, it
means immediate loading. These two points will be described below.
     Immediate load: Indicates that after Hibernate obtains data from the database and assembles an object (such as student 1),
            it will immediately obtain data from the database to assemble the object associated with this object (such as student ID 1).
     Lazy loading: Indicates that after Hibernate assembles an object (such as student 1) from the data obtained from the database, it
            will not immediately obtain data from the database to assemble the object associated with the object (such as student 1),
            but wait until it is needed. Only then will the data be obtained from the database to assemble the associated object.
The cascade attribute of the <one-to-one> element indicates whether the operation is cascaded from the parent object to the associated object. It
can be obtained in the following ways:
     none: When saving, deleting or modifying the current object, it will not be attached to the object. (Associated object) for cascading
          operations. It is the default value.
     save-update: When saving and updating the current object, cascade save and update the attached objects (temporary objects,
          free objects).
     delete: When deleting the current object, cascade deletes attached objects.
     all: Cascade operations are performed in all cases, including save-update and delete operations.
     delete-orphan: Deletes the subordinate object that is disconnected from the current object.
The optional values ​​of the fetch attribute of the <one-to-one> element are join and select, and the default is select.
When the fetch attribute is set to join, it means join fetching: Hibernate
obtains the associated instance or associated collection of the object by using outer join in the Select statement.
When the fetch attribute is set to select, it means that query fetching (Select fetching): you need to
send another Select statement to fetch the associated entity or collection of the current object.

 

 

 

Source: http://blog.csdn.net/java958199586/article/details/7063195

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272634&siteId=291194637