• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Returning "non-Decorated" Entities in JPA

 
Bradley Rintoul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bradley Rintoul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic