Lazy Load Exception org.hibernate.LazyInitializationException:could not initialize Proxy-no Session

Source: Internet
Author: User

Error page Tips

Could not initialize Proxy-no Session

Control Desk

Org.hibernate.LazyInitializationException:could not initialize Proxy-no Session

Illness: This is a lazy use of the exception, using a late load, in the session (Hibernate session), closed after using the object's non-loaded variables, that is, the session is closed, not saved in memory, and then you use, Causes the exception.

Q: I get an object with get, and when the JSP page expresses its instance variable with El, it throws the exception, but it doesn't appear when the application is tested.
A: Presumably the instance variable is hibernate-loaded, and it is possible that hibernate itself is loading the instance variable in the form of load.

Method 1. Using Opensessioninview
Method 2. To disable the delay loading of this class

List=query.list (); for (Object object:list)
Hibernate.initialize (((Deliver) object). Getplnbill ());//deliver is a composite object with attributes referenced in Plnbill


RESULTEXCHANGERATEPOJO.GETDOLLARRMB ();//In its instance variable DOLLARRMB the session is not closed before closing, actually loading it into memory. (I just want to save the value in memory before you can use it before you close the session)

The result: Sure enough, the page is displayed normally.

Summary: The reason is that Hibernate's session has been closed and the collection has not been initialized. In hibernate: Hibernate3 supports lazy loading by default (lazy= "proxy" We can think of as true), Hibernate2 load immediately (lazy= "false").

In Hibernate3, all the lazy properties in the Entity settings file (User.hbm.xml) are set to True by default, which is when the class is not called, delaying loading, which causes the above to occur, and setting the Lzay property to False in the configuration file.


<may-to-one>or<one-to-may> 's Lazy property defaults to: Lazy = "proxy"
Fix:<many-to-one> & <set> set lazy= "false"

If not, according to their own needs, after my careful troubleshooting placed on the set one end, it is placed on the <many-to-one> end.

Lazy Load Exception org.hibernate.LazyInitializationException:could not initialize Proxy-no Session

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: 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.