[Contrib: Evaluation System] Wrapping a method call in a Hibernate transaction/session?

Aaron Zeckoski aaronz at vt.edu
Thu Feb 11 08:46:07 PST 2010


The services have their own wrappers so you should not need to
actually use that unless you are allowing an object to escape the
service methods. In other words, if you get an object from the service
and then try to use it again then things will die because the
hibernate session only lasts for as long as the call to the service
method itself.

If you want to extend the session around the request then you will
need to look at the what is done using the Invoker. The idea there is
that as long as you are using spring to control things it will realize
you already have a spring TX wrapper in place and will not rewrap the
services and DAO (which will cause failures).

Does that help?
-AZ




On Thu, Feb 11, 2010 at 4:23 PM, Jim Eng <jimeng at umich.edu> wrote:
> Hi Aaron,
> I'm back with another question about hibernate session management.  The
> context is pretty much the same as the last two times I asked about this.
>  I'm in a plain vanilla HttpServlet.  I have available these EVALSYS
> singletons:
>     - EvalEvaluationSetupService
>     - EvalEvaluationService
>     - EvalAuthoringService
> Each of these is accessed through its own
> "org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
> with the injected value for "transactionManager" a reference to
> "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager".
>  I thought would mean that my calls to the EVALSYS component would be in
> hibernate session/transactions, but I am still getting errors when I try to
> save an entity that contains a reference to another existing entity.  The
> exception says there is no hibernate session.
> I'm wondering whether I should be using the EvalDaoInvoker to wrap
> everything related to my attempt to save an entity.  We do not want to
> rollback all "create" and "update" actions because one fails, which suggests
> we want transactions at the level of a particular entity.  Suppose I have a
> method to extract an EvalItem from an XML element and save it. The method
> attempts to retrieve an existing EvalItem and update it.  If none is found,
> the method creates a new EvalItem and attempts to save it. If the XML
> element provides an EID for an EvalScale, the method retrieves the EvalScale
> and adds it to the java object representing the EvalItem before saving the
> EvalItem.  I think I need to wrap that entire process in a transaction.
>  Does that make sense?
> From your experience, does it seem like I might need to make explicit use of
> the EvalDaoInvoker to accomplish that?  If so, is the way that's done in
> the inferDefaultViewParameters() method of the EvaluationVPInferrer class a
> good example of how it might be done?
> https://source.sakaiproject.org/contrib/evaluation/trunk/tool/src/java/org/sakaiproject/evaluation/tool/inferrers/EvaluationVPInferrer.java
>
> It's probably been a while since you've worked on this, so sorry to be
> pressing you for ideas.  I hope some part of this might ring a bell that
> might help me.  I've been digging through various docs related to Hibernate
> transactions and such, but in Sakai most of what we do with hibernate is
> several layers removed from the code I'm working on, so I'm not sure how to
> get any control over what I need to without upsetting other parts of the
> system.
> Suggestions welcome.
> Thanks.
> Jim
>



-- 
Aaron Zeckoski (azeckoski (at) vt.edu)
Senior Research Engineer - CARET - University of Cambridge
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ - http://tinyurl.com/azprofile


More information about the evaluation mailing list