Hi, I'm sure this has probably been beaten to death, but I can't seem to
find a viable solution without using spring.

I just switched over to using hibernate from ibatis (so much better now),
and I'm having trouble working my actions around hibernate's transaction
model. With ibatis you had to manually query for linked objects, e.x. a
customer has an address and both the customer and address have their own
table. In ibatis, I was manually wiring these things together with multiple
queries. In hibernate, as long as the mapping is setup, it will wire these
together for me. The problem I'm getting now is related to Lazy loading (the
actual message says the the session has been closed).

As you've probably already figured out, I'm looking up an object from the
database in a method in my action, and calling an object that is a member of
that object in my view. Hibernate tries to pull this from the database, but
notices I already commited the session and gives an error. e.x. in a view
action i will do:

cust = hibernateSession.get(Customer.class, custId);
and in the view:
<s:property value="cust.address.street" />

The solutions I found to this problem when searching are related to using
openSessionInView as an interceptor, but this looks like it's tied to using
Spring. Currently I'm using Guice, but if I must I will switch to Spring.
The other solution I found was a custom built interceptor that extended
AroundInterceptor which I found is deprecated.

What I'm trying to accomplish is opening the session before the action is
called, giving the action access to this session, and having the session
committed after the view is rendered.

Any help is greatly appreciated, and sorry for this being an off topic post.

Thanks,
Will

Reply via email to