The most important attribute of the hibernate face test---hibernate cascade and inverse

Source: Internet
Author: User

The most important attributes in hibernate cascade and Inverse

introduction of a cascade

(1) Casade is used to explain whether or not an action on the main object is associated with a similar operation from the object, commonly used cascade:

None,all,

Save-update, delete, lock,refresh,evict,replicate,persist,

Merge,delete-orphan (One-to-many)

In general, Many-to-one,many-to-many is not set and cascading is set in <one-to-one> and <one-to-many>.

(2) Whether the cascade operation on the main object is also to operate from the object, which embodies the idea of cascading

(3) Cascade is best to set the number of the main object, when the query is updated order, update customers

(4) When the cascade is set to more than one side, it will first save a party, and then save more side. The SQL statement executed is:

Hibernate:insert into Customers (realname, pass, sex, petname, email, rdate) VALUES (?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

(5) When the Cascade set to one side, will first save a lot of the side, because when the more than one side, there is no foreign key, so when the insertion of a side of the party will be updated more than a side, the implementation of the results are:

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into orders (number, address, phone, odate, sum, status, CID) VALUES (?,?,?,?,?,?,?)

Hibernate:insert into Customers (realname, pass, sex, petname, email, rdate) VALUES (?,?,?,?,?,?)

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

Hibernate:update orders set number=?, address=, Phone=, odate=, sum=, status=? where id=?

This is the best evidence to persuade the cascade to put more than one side, so the norm is written:

Add cascade= "Save-update" to more than one side

two inverse whether to waive the right to maintain

1. Inverse is the decision on which side of the two-way association to maintain the relationship between the table and the table, in the absence of settings, both sides are maintained, set the parameters are:

True indicates that giving up the right to maintain can increase efficiency

False indicates that the maintenance rights are not waived

2. The setting principle is:

In a one-to-many relationship, the party who is on one side is set to be the active party, and the party in one gives up the right to defend

Add cascade= to "save-update" on many sides

On one side, add inverse= "true"

3. Inverse indicates whether to maintain an association between the two, and the default value of inverse is false, which indicates that the associated relationship is maintained, and when set to true, the associated relationship is not maintained. When used in one of the parties should give up the maintenance of the relationship, to improve efficiency. That is, the one side is set to Ture, and by default, both parties maintain an associated relationship.

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.