Cascade Add Action Value when the current data is manipulated. The associated data is also manipulated, that is, the colleague who holds the current data will also save and modify the associated data
First, the relationship between objects is bound;
' Add a Multiparty object to a collection of party objects
Tm.getstudents (). Add (SM1); Tm.getstudents (). Add (SM2);
To set the association object of a multiparty object to one side,
Sm1.setteacher (tm); Sm2.setteacher (tm);
Then add the Teacher object.
S.save (tm);
Cascading associated objects when setting teacher objects
<set name= "Students cascade=" Save-update >
Eg: after setting the cascade= "Save-update" property in the class set element, when the corresponding teacher object is saved, the data is stored in the collection with the variable student, and if there is data, the object is cascaded. If the object is cascaded to, only want to save operation, spit over the object when it is cascaded Po, perform the update operation.
Note:
1, the current into the settings of the teacher to the student cascade, so save the teacher, you can cascade student objects, but save students are unable to cascade teacher object, can be set by the Many-to-one element of the Cascade property to complete the students to the teacher cascade.
2, if the cascade operation is not set, and the teacher object with association relation is saved, the Gray Association is running out of the exception;
Focus:
1, if the current teacher object to, but Po, can also remember the above operation, but because there is already data in the PO object first-level cache, so the UPDATE statement is executed
2, if the teacher object is associated with the student object is not to, but Po, is cascaded, not the save operation, but the update operation;
3. If the teacher object in the database already has the associated student data, and the operation is the teacher data using do data, will have a relationship change,
4. Cascading can set up multiple parties, but the general development of a party can be set;
hibernate--cascading Additions