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