• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IdClass & lazy initialization

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have:
1. A persistent object with an IdClass as key
2. A stateless session bean that gives a method that returns my persistent object using the 'getReference()' method
3. A servlet that invokes the stateless session bean

I'm using J5EE+JBoss 4.2.0.

When I get my object in the servlet, if I try to invoke the getter of any of the 'id' fields, I get an error about the lacking of the session (Hibernate session).
I noticed that:
1. If I use the 'find' method, this problem does not occur
2. If I use the EmbeddedId key for my persistent object, this problem does not occur

Is this normal? What's wrong with the use of my persistent object?

Considering that it seems that, outside the session bean, all the lazy fields not yet loaded are unaccessible, it's very risky to return a persistent object from a session bean. Is it true? How should I approach such a situation? Returning a lightweight version of the same persistent object?

Thanks in advances!
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,
in general, what can I read from a persistent object that is returned by a session bean?

Thanks in advances
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoting from the spec:



I think you may:
1.Consider using find() instead of getReference() or
2.Use getReference() and Consider explicitely fetching all the entity attributes before it is detached as the container might have not loaded them due to lazy loading.
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic