Hibernate Inverse properties and Cascade properties

Source: Internet
Author: User

Inverse Property

The inverse property is useful when maintaining an association relationship.

Indicates whether control is transferred. (works on one side)

Inverse, control reversal.

Inverse = false does not reverse; when there is control over the front

True control reversal; current party has no control

To maintain an association relationship, set the inverse property:

1. Save your data

have an impact.

If you set control inversion , that is inverse=true, then the Association is maintained through the departmental side. While saving the department, the data is saved, but the relationship is not maintained. The Foreign key field is NULL

2. Get Data

None.

3. Disassociate relationships?

have an impact.

Inverse=false , can be de-correlated

inverse=true , the Current party ( Department ) has no control and cannot disassociate the relationship

( no update statement is generated and no error is produced )

4. What is the effect of deleting data on an association?

have an impact.

Inverse=false, with control, can be deleted. Empty the foreign key reference before deleting the data.

Inverse=true, no control: If the deleted record has been referenced by foreign key, will error, violate the main foreign KEY reference constraint! If the deleted records are not referenced, you can delete them directly.

Cascade Property

Cascade indicates that a cascade operation "can be set to one or more of the other side"

None cascade operation, default value

Save-update Cascade Save or update

Delete Cascade deletion

Save-update,delete Cascade Save, UPDATE, delete

All ibid. Cascade Save, UPDATE, delete

Hibernate common interview question: Inverse and cascade difference?


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hibernate Inverse properties and Cascade properties

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.