I use a Hibernate.initilize() call in the DAO layer for every object I need to see in the presentation layer (common jsp files).it avoids Lazy Initializations without passing Hibernate Proxy around layers. It works fine for me
2009/7/15 Nathan Schulte <nathan.schu...@ngc.com> > I'm currently using Struts2 in a project that is utilizing the Java > Persistence > API (JPA, specifically Hibernate) with container managed transactions > (CMT). To > access the Persistence layer, a layer was created using SLSBs as "service" > objects which provide simple "<entity_type> get<entity_type>ById( int )" > and > "List<<entity_type>> get<entity_type>s()" type methods. The Struts2 > Actions use > these beans (by injection (provided by some interceptor, such as the EJB3 > Plugin) or a JNDI lookup, it doesn't matter really) to get the instances of > the > entities. > > Up until now, all of the properties of the entities that were being > accessed to > create the view were either eagerly fetched associations, or private > members of > the entity. Recently, I have the need to start using lazily fetched > associations (self joins and the like), and need to find a way to extend > the > Persistence context through to the view generation. > > Although there isn't much need to explain, the error I am receiving is the > following: > ERROR [LazyInitializationException] failed to lazily initialize a > collection of > role: <private_member_name>, no session or session was closed > > I noticed recently that there was a "Full Hibernate" Plugin that supports > injection of a Session (presumably into an Action?) and will close the > Session > after the view generation. This works fine for application managed > persistence, > but does not solve the issue of when using CMT (or at least to my > knowledge). > > Searching the web for solutions to the problem resulted in a suggestion to > create an interceptor (that runs after the Action, but before the view > generation?) that does a JNDI lookup to create an EntityManager (extending > the > Persistence Context to the interceptor, I think). I'm not sure what this > was > supposed to resolve, but I have not tried this as 1) I'm not sure how to > create > such an interceptor and get it to "intercept" at the appropriate time, and > 2) I > don't think this would resolve anything, as I don't think this would really > extend the Persistence Context through to the view generation. > > How are others resolving this issue and using lazy initialization? > > I have a few more ideas as last resorts, but I don't want to taint the > responses, so I will hold onto them for now. > > Thanks, > -Nate > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >