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