aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Returning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Returning "non-Decorated" Entities in JPA" Watch "Returning "non-Decorated" Entities in JPA" New topic
Author

Returning "non-Decorated" Entities in JPA

Bradley Rintoul
Greenhorn

Joined: Apr 01, 2003
Posts: 14

I have a problem which I'm pretty sure bumps up against some fundamental issues of JPA and managing the persistence of objects in general (and my lack of understanding of it) ...

So, I have a stateless session bean which simply uses an EntityManager to find an object by its primary key. This entity object has a one-to-many association which I would like to be lazily loaded. This is all pretty much fine and dandy. Now, when I try to return this object through a web service (JAX-WS 2.1) using JAXB for the binding, I get a lazy- load-outside-of-a-session-fial. I'm no stranger to these, but isn't there some way that I can "completely detach" my nice little object so that it doesn't have the proxies or whatever hanging around it so that the call to "get" the list just runs the code in the getter (which checks for null list and creates empty list)?

Is what I've written making enough sense to get some help..?
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Bradley,

You are using Hibernate I am assuming? If so, one option is to switch persistence providers. TopLink/EclipseLink/Kodo/OpenJPA handle lazy loading more gracefully. The other option, of course, is just to implement the Object.clone() method and get an "unadulterated" copy when you need it :-).

Hope this helps,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Bradley Rintoul
Greenhorn

Joined: Apr 01, 2003
Posts: 14
Reza Rahman wrote:Bradley,

You are using Hibernate I am assuming? If so, one option is to switch persistence providers. TopLink/EclipseLink/Kodo/OpenJPA handle lazy loading more gracefully. The other option, of course, is just to implement the Object.clone() method and get an "unadulterated" copy when you need it :-).

Hope this helps,
Reza


Yes, I'm using Hibernate. Yeah, I thought about doing some sort of a "clone" operation or something... What I have done which *appears* to have gotten around the problem was called "set<thing>" with a null argument. I was thinking that would choke, but somehow it managed to circumvent the problem. Kinda odd that there isn't a simple way to turn a detached object back into a true "POJO"...

Thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Returning "non-Decorated" Entities in JPA