Cascading, delayed loading, and inverse attributes of Hibernate

Source: Internet
Author: User

The cascade function of Hibernate is used to describe the relationship between two tables in the database (one --- to --- one, one --- to --- tables, tables --- to --- tables ). When you perform some operation on the primary object, whether to perform the corresponding operation on its associated sub-objects.

Common cascade include:

(1) None: indicates that no operations are performed on cascading objects during storage, modification, or deletion. It is the default value.

(2) Save-Update: indicates that the affiliated objects are saved and updated cascade when they are saved and updated.

(3) Delete: indicates that the secondary object is deleted cascade when the current object is deleted.

(4) All: Indicates cascade operations in all cases, such as Save-update and delete operations.

(5) delete -- orphan: the orphan object that is detached from the current object is deleted when the current object is deleted. (Applicable only to one-to-many instances .)

 

Lazy load: this technology is widely used. This delay load ensures that the application can capture the corresponding data records from the database only when necessary, by using the delayed loading technology, you can avoid loading too much data in the database table too early, thus reducing the application memory overhead. The delayed loading of Hibernate is essentially a proxy mode. When a program loads an object through hibernate, by default, Hibernate does not immediately capture its set attributes and records associated with entities. Instead, a proxy is used to generate these set attributes and associate entities. This is the advantage of proxy.

For example, in a cascading relationship: department ----- employee (one --- employee) table, when performing some operations, set lazy to true to optimize its performance.

 

The inverse attribute of hibernate: inverse is the basic concept of bidirectional relationship. Of course, for most entities, we do not need bidirectional Association, but more importantly, we need to select a single association. Improper use or setup of inverse may lead to performance degradation, resulting in redundant SQL statements and even JDBC exceptions. For example, in two-way association, if both inverse and inverse are set to true, neither party will maintain the relationship update. If both sides are set to false, this will inevitably cause both parties to maintain the same relationship. Therefore, it is best to set inverse to true at one end and inverse to fase at one end in two-way Association. Generally, inverse = fase is placed on the producer end.

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.