Hibernate Learning Note 4 delay loading and correlation mapping

Source: Internet
Author: User

One, delayed loading

* When using hibernate methods to query data, only an empty object is returned (except the id attribute is null), and there is no real query database, but in the use of this object will trigger the query database, and inject the data into this empty object. This mechanism of actually deferring queries to object access is called lazy loading.

* Benefits: Can increase the utilization of memory resources, reduce the number of access to the database.

* Method: Session.load ()/query.iterate ()/loading of associated properties in the correlation map

* Note: Avoid closing session prematurely before using the object

--1. Use non-deferred query data, such as Query.get (). Session.list ()

--2. Use the object and then close the session

Second, the association mapping

* Definition: If two tables have an association relationship, we configure this relationship in the entity object and the mapping relationship file, and then use Hibernage to manipulate one of the tables, it can automatically help us operate to another table by configuring the relationship, which is called Association mapping by configuring the automatic operation of another table.

* Associated mapping operations include:

-Correlate queries out of relational table data

-Correlate new and modified data for relational tables

-Correlate data for deleting relational tables

* Types of relationship mappings:

1. One-to-many association: operation "A" to operate "many", including query, add, modify, delete.

Use

HBM Mapping File configuration:

2. Many-to-one correlation

3. Many-to-many associations

4. One-to-one correlation

5. Inheritance Association

   

Hibernate Learning Note 4 delay loading and correlation mapping

Related Article

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.