File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Lazy initialization and IdClass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Lazy initialization and IdClass" Watch "Lazy initialization and IdClass" New topic
Author

Lazy initialization and IdClass

Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
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!


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lazy initialization and IdClass
 
Similar Threads
IdClass & lazy initialization
[SCBCD5] Lazy values returned from sb
please answer these sun j2ee test questions
My SCEA Part 1Study Notes
J2EE Recommended Reading