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.