| 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: 559
|
|
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!
|
 |
 |
|
|
subject: Returning "non-Decorated" Entities in JPA
|
|
|