Hibernate lazy load.

sponsored links
HIBERNATE the persistent object is loaded strategy.
Lazy loading, which is used when loads go. This will improve some performance.
Hibernate's lazy loading a HibernateSession used to manage the session, its logic is a database of each operation, on opening the new session, immediately after the operation is complete turn off the session. The benefits of doing so is strictly closed session, to avoid the mistakes rookie class, but does not recommend doing so hibernate.org. This does not fit because lazy loading, does not fit cross Ways affairs.

For instance in our application, user-> post the formation of one-to-many mapping, User, there is a post that contains the List.
User at, there are a number of property: name, password, phone, etc., there is a List type of posts. When we use the lazy laoding on the posts when, hibernate will get User Object when the return is only name, password, phone and other basic property, when you visit the posts, it only posts from the database to extract the necessary data, this is the so-called lazy laoding. However, in our system, session are immediately closed, that is, read the name, password, phone, etc. After the basic property, session has been close, and again there will be lazy loaiding abnormal.
The solution is to close session before the call Hibernate.initialize (user.getPosts ()), tell the system, user.getPosts () are the lazy laoding required. But to do so would undermine the kind of package HibernateSession.
Later, using the so-called OpenSessionInView model put to the session of the cycle to manage the servlet filter, whenever the request has come in, it opens a session, response and then turn off after the end of it, this will enable the session exist in the entire request cycle.

Lazy lazy loading in Hibernate
Hibernate-related one-to-one and many-to-one in the query client's father, lazy problem
Hibernate3 association at this lazy have on property, if it is Hibernate2, should be set outer-join = "false", then the object has been associated, in the place settings class that lazy = "true". First of all, for many-to-one of questions, you can end the class at his father to set up tag lazy to resolve, so that at query time when his son, does not send redundant sql.
For one-to-one, at hibernate2 inside, because of one-to-one There are no lazy options so only by setting outer-join = "false" to resolve. And Hibernate3 has joined the lazy, so will not have this problem.
Generally speaking, if you find that you query the time his son, has extra sql to send, then yes you must hibernate misuse ..

Hibernate at the one-to-many, many-to-one, many-to-many, in order to improve efficiency, we are generally lazy mechanism used, but the use of spring's getHibernateTemplate (). Save (Object), when, HibernateTemplate attempt execute at each time to get before the Session, and strive to turn off on the implementation of End of Session. This means that Hibernate's Lazy initialization 1: n relationship, you must ensure that are in the same Session for internal use on the relationship between the collection, otherwise Hiernate will be dished out Failed to lazily initialize a collection - no session or session was closed exception.

Hibernate objects in the correlation (association) of the set is not enough flexible and practical applications required in some places lazy load, and some places also do not need to, in fact, there is no need to use places on the association. In Hibernate, only alluding to the document set at a way of applications such as ours, are not easily use my open session in view of (slowly is better than living lock), but are either not set up association or is the lazy = true. Previously classified information only in a many to one relationship, the price can also be put up, but now more and more complicated relationship, and then a few more, then we have to pay for performance, bandwidth costs, etc. I am afraid we can not overlook, Even if the use of cache that enhance performance, waste of bandwidth is still unforgivable.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Hibernate lazy load.

  • Rails: a model with different access to the design of access control

    And want to discuss a U.S. rails access control design problem. If I have a user's model, by its implementation, deleted, changed, the list of functions. Ordinary circumstances, we will achieve similar Scaffold generated code. Default into a user ...

  • PeriodicalExecuter object in prototype.js

    prototype.js defined PeriodicalExecuter object, provide a certain interval of time to repeat the logic of a method call. <div></div> <script> var i = 0; var p = new PeriodicalExecuter(showTime,0.1); //Create the instance. Each 0 .1Second

  • Web safety test of cross-site request forgery (CSRF) articles (Figure)

    Cross-site request forgery (ie, CSRF) has been referred to as Web security sector number of loopholes in the "sleeping giant", and its level of threat which "reputation" will be shown. This article will briefly explain the loopholes, a

  • Spring and Hibernate Integration

    1. Management SessionFactory Spring Integration to use Hibernate, we do not need to file hibernate.cfg.xml. First, in the applicationContext.xml to configure the data source (dataSource) bean and the session factory (sessionFactory) bean. Among them, the

  • hibernate study of the second

    Persistence of three main points: 1, a statement for persistent fields accessors (accessors) and whether the variable signs (mutators) Property statement is not necessarily required for the public's. Hibernate can be default, protected or private ...

  • JS after ajax request return of the problem can not be implemented

    1: Send ajax request, in the onComplete, if back when the html contains a javascript, then these javascrip and will not be realized, it does not mean not to implement. This problem has troubled me for a long time, behind the hair and then put this kn ...

  • Commonly used version control software

    Commonly used version control software According to view the network information, see the general use version control software as follows: (One of the level of reviews from one of http://www.hansky.com/cn/news/select_scm3.html but there is no introdu ...

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • JAVA Class naming convention

    1. Entity Layer: Inheritance: All categories inherited from BasicEntity, one of BasicEntity implementation java.io.Serializable interface; Naming rules: Class Name = Object + type suffix, one of type suffix for Bean, such as: SalesOrderBean 2. Form l ...

  • Application of spring struts2.0 hibernate HQL

    Therefore, in the development of statistical inquiry system, as far as possible through the use of select statement to write the required query property way back relational data, and avoid using the first query return persistent object (in this way are in

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries