hibernate--cascading Additions

Source: Internet
Author: User

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

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.