Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Lazy Policy in Hibernate

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shares with you the content of a sample analysis of Lazy policies in Hibernate. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Hibernate Lazy uses CGLIB to proxy classes, which can be used to:

Class: value can be true,false. Default is true.

Property: you can take true,false as the value, and class enhancement tools are required.

Collection: true/false/extra

One-to-one,many-to-one: take false,proxy/noproxy

Hibernate lazy concept: it is created only when the object is actually used, and for Hibernate, a sql is issued only when it is actually used.

Test class Hibernate Lazy: check id does not send sql, because you pass is the primary key, look up other attributes will send sql,Hibernate Lazy validity period must be session in open can be, the solution is to use openSessionInview.

When testing the set Hibernate Lazy:get collection, it will not send sql, but the iteration will send sql, and when checking the number, it will find out the whole collection, which has an impact on efficiency.

When the lazy of class is set to false, the common properties will be checked out in the load class, but the collection will not be checked.

The lazy on the class tag does not affect the lazy feature on the collection.

The lazy feature on the class tag works only with normal attributes.

Lazy uses extra on the collection to issue count statements when getting size, which improves efficiency.

By default on single-ended associations, lazy, like collections, returns the agent when get does not issue query statements, but issues sql when used.

On the lazy=false on the single-end association, issue two sql when accessing the common attributes, and query the attributes and the corresponding associated objects.

Set lazy on the class tag to false, other defaults: does not affect single-ended associations, nor does it affect collections.

Thank you for reading! This is the end of this article on "sample Analysis of Lazy policies in Hibernate". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report