Assume that the customer and orders establish a one-to-multiple bidirectional Association.
Inverse attributes:
// Load the Persistent Object
Customer customer = (customer) Session. Load (customer. Class, new INTEGER (2 ));
Orders order = (orders) Session. Load (orders. Class, new INTEGER (2 ));
// Establish Association
Order. setcustomer (customer );
Customer. getorders (). Add (order );
Because hiberante automatically clears persistent objects in the cache and synchronously updates the database based on changes in the Persistence State, although the above Code only modifies
One record in the orders table will still execute two update statements because the state of the Persistent object in the memory has changed twice.
This redundant SQL statement affects the performance. To solve this problem, set the value of the inverse attribute to true.
Summary:
When a one-to-multiple bidirectional Association is specified, the one-party inverse attribute value is set to true.
When establishing two-way associations between two objects, you must modify the attributes at both ends of the Association at the same time.
Cascade attributes:
When the property value is
Save-Update: indicates that when the current object is saved or updated, it is saved or updated in cascade mode.
Delete: (cascade delete) cascade Delete the associated objects.
All-delete-orphan: automatically deletes sub-objects that are no longer associated with the parent object. In the preceding two cases, the above two functions are executed.
It can be said that it is a fully automated property value.
In general, when there is a parent-child relationship between the two parties, you can set the cascade attribute value of the parent to all-delete-orphan.
Parent-child relationship: the parent controls the lifecycle of the child. The child object must be associated with a parent object. The child object cannot exist in isolation.