Cascade and session operations

Source: Internet
Author: User

Each cascade setting of hibernate corresponds to a session method.When you call this method to process an object, if the object has an associated object configured with this method for Cascade, the associated object will be processed in the same way!

The following cascade settings are provided in total:

Package org. hibernate. Annotations;

/**
* Cascade types (can override default ejb3 Cascades
*/
Public Enum cascadetype {
All,
Persist,Persist operations
Merge,Merge operations
Remove,Corresponding remove operation
Refresh,Corresponding refresh operation
Delete,Corresponding delete operation
Save_update,Corresponding save, update, saveorupdate operations
Replicate,Corresponding replicate operation
Delete_orphan,
Lock,Corresponding Lock Operation
Evict,Corresponding evict operation
}

 

You should be familiar with the last six types of interfaces. They are all cascade options corresponding to some interfaces in the early sessions.

The four green functions are actually no different, but they are the four interfaces supported by JPA specifications. I think one of the main reasons why hibernate sessions introduce these four interfaces is that when we use JPA standard annotations to prepare cascading, these four cascade options are available, if you want some cascade settings to take effect, the session must provide the corresponding method!

 

For example:

Public class item {
...
@ Onetoetype (cascade = {cascadetype. persist,
Cascadetype. merge,
Cascadetype. Remove },
Mappedby = "item ")
Private set <bid> bids = new hashset <bid> ();
...
}

At this time, if we call session. persist (item), all bids in its bids set will also be together with persist.

However, if you use session. Save, no.

In general, cascade-to-one and sequence-to-sequence do not use cascade operations very well. One-to-one and one-to-one are the most common cascade operations!

A

A

A

A

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.