-
1. Re: Howto fetch lazy relations before an entity is detached
jaboj Apr 26, 2006 3:07 AM (in response to scraatz)It seems like JBOSS has some inexpedients about LAZY loading. We're experiencing the same problem that you describe.
If I fetch a entity with a LAZY loaded relation into a statefull session bean, then I'm only able to get attributes from the lazy loaded relational object in the same call to the session bean (using CMP). In subsequent call to the sessionbean I will not be able to retrieve attributes from the LAZY loaded relation. This means that when we initialize a statefull bean we'll try to avoid lazy loaded objects by using queries instead - otherwise we'll create a transfer object for the lazy loaded objects on initialization.
I've have changed a lot of em.find() to EJB queries instead, where the query (using [LEFT] JOIN FETCH) is fetching alle the neccesary relations needed to avoid lazy loading.
I also think it's a problem that even after loading a LAZY loaded relation the objekt is still a proxy-class type (Ex Company will be of type Company@EnhancerByCG.....) This means that we can't use intanceof to determing the object type of inherited objects in that case. -
2. Re: Howto fetch lazy relations before an entity is detached
berkum Feb 16, 2007 12:18 PM (in response to scraatz)I do have the same problem, need to iterate through the whole collection to make object available outside the persistence context. I am passing persistent object to web layer. With hibernate, according to the api, you can use Hibernate.initialize() to initialize your Collection. There doesn't seem to be anything planned in jpa for such task. Anyone knows ?