S2JH Hibernate Lazy Crawl Strategy--could not initialize ProX

Source: Internet
Author: User

This error occurs when you do a picture upload related entity save.

Related entity

@OneToMany (Mappedby = "ObjectSid", cascade = Cascadetype.all, Orphanremoval = True) @OrderBy ("Orderindex desc") Publ    IC list<objectr2pic> getshoppagepics () {return shoppagepics; }

Controller

@Override      @MetaData ("Save")     public httpheaders dosave ()  {        List<ObjectR2Pic> shopPagePics =  Bindingentity.getshoppagepics ();        if  (! Collectionutils.isempty (shoppagepics))  {             for  (objectr2pic shoppagepic : shoppagepics)  {                 shoppagepic.setobjectsid ( Bindingentity.getid ());                 shoppagepic.setobjecttype (objectpictypeenum.shop_page_pic);             }        }         return super.dosave ();     } 

The program is executed to

list<objectr2pic> shoppagepics = Bindingentity.getshoppagepics ();

Always get the picture information of the front end, so the next report is abnormal

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

hibernate error caused by delayed initialization, at which point the proxy class instance or proxy collection is in Free State, at which time he is initialized, the error will be reported. Some netizens put forward, set the fetch crawl strategy lazy lazy mode is true, but also some netizens proposed such settings for memory, and performance unfriendly.

WORKAROUND: After careful investigation of S2JH's parent class, the original @S2JH has resolved the problem, which is pre-initialized lazy collection before use.

Append to Controller:

@Override protected void setupdetachedbindingentity (Long id) {bindingentity = Getentityservice (). Finddetachedon    E (ID, "shoppagepics"); }

The persistent understanding of the individual hibernate is still not in place, if there is an expert to see, hope to be in the comment area pointing twos. For the shallow point of the article, please criticize it a lot.

S2JH Hibernate Lazy Crawl Strategy--could not initialize ProX

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: info-contact@alibabacloud.com 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.