|
From: Colin S. <col...@ex...> - 2003-09-04 21:10:58
|
I was using the TransactionProxyFactoryBean with the
HibernateTransactionManager, but when I switched to the
JTATransactionManager, got bitten by the fact that I no longer had
anything creating a Hibernate session and binding it to the current
thread, as HibernateTransactionManager used to do by default.
One verbose solution would have been to have gone back to the old
ProxyFactoryBean mechanism for handling transactions, and just stack a
HibernateInterceptor in front of the transaction interceptor.
I decided instead to make a Hibernate specific verison of
TransactionProxyFactoryBean. All it does is take a new
HibernateInterceptor property, and in afterPropertiesSet add the
interceptor before the transaction one (however, unlike the transaction
one, it will execute on all invocations, since you may want to run some
methods with a hibernate session, but no transactions.
// allways invoke the Hibernate Interceptor
addInterceptor(hibernateInterceptor);
... existing code to set up the Transaction interceptor
Now my questions:
1: is it worth checking something like this in? I made a cut and past
copy of TransactionProxyFactoryBean, and added the new property and
modified the afterPropertiesSet. Obviously, I could also have just
subclasses the existing class and overriden afterPropertiesSet. That's
probably a better choice, but maybe a bit more dangerous if something
changes in the parent method which is no longer called at all.
2: is there a better way of doing this? I supposed I could have wrapped
the proxy in another proxy to add the hibernate interceptor. This would
not have required any code changes, but would have made for a lot more
typing in the context. Another option would be to add optional before
and after, 'always invoke' interceptor properties to the
TransactionProxyFactoryBean, so something like this can be added.
Regards,
Colin
|