• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

JPA2.0 Lazy Load collection(one-Many) attribute and retriving after em.close()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to lazy load a collection attribute in an entity and retrivie it after calling entityManager.close().Which i mean retrival out of the entity manager context.

Am using Hibernate flavor of JPA which is of version 3.6.8

Code template might look like this

EntityManager em = (retrive from factory)
SampleEntity se = em.find(SampelEntity.class,45);
em.close();
se.getXXXCollection() - Here i required a lazy loading to happen out of the enity manager context

It would ideally throw a "failed to lazily initialize a collection" exception but thought of getting some suggestions from the forum whether is there any solution.

Please suggest.

Thank you
Mohan
 
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No you can't.

You should define your data methods well enough that they do only 1 thing, and is clear on what they do.

Closing the EntityManager suggests that that method's task is done already.

Do NOT do lazy-loading outside your data layer.

-k


[SpringSource Certified Spring Professional - Practice Tests]
 
mohan dilli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Kathleen Angeles!!!

Does anyone implemented @proxy concept of hiberante to override the proxies generated by hibernate during lazy loading of collections?Can i be able to achieve out of context lazy loading by my own implementation of proxies? Not sure what am asking is right.Please suggest
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if you did implement something like this, you would run into the risk of dirty reads.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic