Hibernate cascade (Cascadetype attribute of hibernate annotations)

Source: Internet
Author: User

"Problems encountered by your project":

New delete can be implemented, that is, when the change cannot be synchronized update design three classes: Problem class Scask body content class Text Class View number + reply number + discussion number of Runinfo class

"Body class and number of views + replies + Number of discussion classes cannot be modified update"

Background changed annotation success

"Reference blog: http://blog.sina.com.cn/s/blog_9b81777f0101gn3f.html"

Cascade representing cascading operations


Cascadetype.merge Cascade Update: If the Items property is modified then the order object is saved and the objects in items are modified at the same time. The merge method corresponding to Entitymanager


Cascadetype.persist Cascade Refresh: Gets the object in the order object that also retrieves the latest items at the same time. The Refresh (object) method corresponding to the Entitymanager is valid. will re-query the latest data in the database

Cascadetype.refresh: The objects in items are also saved when the order object is saved. The Presist method of corresponding Entitymanager

Cascadetype.remove Cascade Delete: Delete the Order object as well as the objects in items. Remove method corresponding to Entitymanager

Cascadetype.persist a cascade B object is added when only Class A is added. If the B object is in the data inventory (followed by the new) then throw an exception (let B become persistent state)

Cascadetype.merge refers to a class of new or changed, cascading B objects (new or changed)

Cascadetype.remove only Class A delete, cascade delete Class B;

Cascadetype.all contains all;

Cascadetype.refresh didn't work.

In general: Most of the cases with Cascadetype.merge can achieve cascade with new and not error, use Cascadetype.all to consider Cascadetype.remove

@Fetch:

Defines the fetch policy that loads the associated relationship. Fetchmode can be

Select (Triggers a SELECT operation when an association is required), Subselect (valid for collection only, subquery policy is used, details refer to Hibernate reference document)

Join (Use SQL join to load the association relationship when loading the primary entity).

Join will overwrite any deferred attributes (the associations loaded through the join policy will no longer be deferred).

Hibernate cascade (Cascadetype attribute of hibernate annotations)

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.