Jürgen,
I spent some time and created a test app under the autobuilds tree to
verify the new code you put in to allow binding a Hibernate session to
the JTA transaction in a CMT environment, with no Spring
TransactionManager around. Essentially all the test does is call a
Stateless EJB, which then verifies that two calls to
HibernateTemplate.execute give the callback the same session. With no
TransactionManagerLookup in the Hibernate config, the sessions are
different. When the TransactionManagerLookup is added, the sessions are
the same, so all seems to be working ok.
I also verified in the log the result when another test method throws a
DataAccessException while in HibernateTemplate.execute, and the session
does get properly unbound from the thread, and then closed().
The test app I created is called ejbtest, and presumably it can be used
for any tests of this sort with EJBs. It uses Cactus to actually drive
the tests, as that seemed the easiest.
Regards,
Colin
jürgen höller [werk3AT] wrote:
>Thanks in advance - any test code will do. You don't even need actual Hibernate operations: Open two HibernateCallbacks via two execute calls within an EJB transaction, and see if you receive the same Session.
>
>The most important point is proper cleanup, so please check via the debug log whether the Session gets properly unbound at transaction completion - even if an exception gets thrown. I just noticed that I'll need to add a try/catch for flush failures, just like with JtaTransactionManager; gonna change that promptly.
>
>I tested this stuff on Resin with plain JTA, and it worked nicely. Conceptually, there shouldn't be any issue with other JTA implementations or EJB CMT, but I'd like to make sure that it actually works there too :-)
>
>Juergen
>
>
>-----Original Message-----
>From: spr...@li...
>[mailto:spr...@li...]On Behalf Of
>Colin Sampaleanu
>Sent: Thursday, April 08, 2004 1:10 PM
>To: spr...@li...
>Subject: Re: [Springframework-user] tx/session not getting unbound
>during rollback
>
>
>Juergen,
>
>I'll have to make a test app of some sort to test this out properly with
>CMT and a session bean. Our only remaining usage of EJBs now is a
>message driven bean that is still around, and even before, we were
>delegating to spring pojo objects, which did sometimes need to be
>wrapped, so this setup wouldn't have been appropriate.
>
>I'll try to dig up some old code and do something...
>
>
>jürgen höller [werk3AT] wrote:
>
>
>
>>I've just committed a reworked version of SessionFactoryUtils to CVS HEAD. It uses a simple and straightforward approach to synchronize with JTA: If Hibernate configuration contains a TransactionManagerLookup, it will fetch the TransactionManager reference from the SessionFactory and register a JTA Synchronization that flushes and unbinds the Session at transaction completion.
>>
>>So essentially, you can now have transaction-scoped Sessions with either JtaTransactionManager (no need for special Hibernate configuration) - or plain JTA / EJB CMT, without JtaTransactionManager being involved (needing a Hibernate TransactionManagerLookup). For EJBs, the latter should be a convenient way to work with Spring's standard Session management.
>>
>>Joshua, I've looked at your code and noticed that you're auto-applying a JtaTransactionManager. This isn't really necessary - I know, just easy to tell if you know the internals ;-) I think that the solution that I've just committed is significantly simpler: It doesn't need any special consideration, except the need for a TransactionManagerLookup in Hibernate configuration. For everything else, stick to standard Spring API.
>>
>>Colin, I'd be grateful if you'd give this a try with EJB CMT. A simple Stateless Session Bean that invokes two Hibernate DAO methods would be enough to test this: The data access operations should still work on the same Session, completely without Spring's JtaTransactionManager being involved (as long as there is a Hibernate TransactionManagerLookup).
>>
>>Juergen
>>
>>
>>________________________________
>>
>>Von: spr...@li... im Auftrag von Patrick Burleson
>>Gesendet: Mi 07.04.2004 05:04
>>An: spr...@li...
>>Betreff: Re: [Springframework-user] tx/session not getting unbound during rollback - what am I missing?
>>
>>
>>
>>Joshua Davis wrote:
>>
>>
>>
>>
>>
>>>I was wondering if anyone was interested in the JTA->Spring sync code I
>>>wrote. It has helped ease the transition from legacy EJBs into
>>>Hibernate/Spring. What's the best way that I could contribute it to Spring?
>>>
>>>
>>>
>>>
>>>
>>>
>>I would certainly be interested in looking at that code. Feel free to
>>email it to me if you can't find a place to put it in Spring.
>>
>>Thanks,
>>Patrick
>>
>>
|