Cascade of hibernate-cascade operations

Source: Internet
Author: User

 

In hibernate, the configuration file for persistent objects contains the cascade attribute, as the name implies, cascade, that is, when

Operations on the current object will affect the associated entities configured accordingly. For example, when you save the current object

The object associated with it. Of course, the generation of this additional operation depends on whether you have configured the element of the associated object in the configuration file of the current object.

Cascade attribute.

 

Cascade operations may involve adding, modifying, deleting, and other database operations. The specific cascade value is

It can be divided into multiple types. For example, all indicates that all operations are cascade. For example, save-Update indicates that cascade operations are performed on inserts and modifications. Pair

The value of cascade depends on the specific requirements. Here there is no unified standard for the value to meet your needs. From reality

Demand analysis determines how values should be taken.

 

ALL ::           All associated operations are performed.
None:            No association operation is performed in all cases. This is the default value.
Save-update:     Perform join operations when you execute save/update/saveorupdate.
Delete:          Perform the join operation when executing the delete operation.

All indicates save-update + Delete.

All-delete-orphan indicates that when an orphan node is generated in the object graph, the node is deleted from the database.

For example, all-delete-orphan:
The relationship between category and item is one-to-multiple, that is, there is a set type variable in the category class items. For example, there are two

Item, Item1, item2. If the definition relation is all-delete-orphan, when an item is deleted in items (for example, it is deleted using the remove () method.

Item1), then the deleted item class instance will become an orphan node. When category. Update () or session. Flush () is executed, Hibernate is the same

Step cache and the database will delete the records corresponding to Item1 in the database.

 

Refer to blog:

Http://dreamzhong.iteye.com/blog/1273157

Http://apps.hi.baidu.com/share/detail/5946383

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.