|
From: Brian M. <br...@ap...> - 2004-12-16 15:30:24
|
If I am using both hibernate and a raw datasource in an application, is
there a mechanism for having them both work in the same transaction
other than JTA?
The LocalSessionFactoryBean is configured to use the same data source
as I am attempting to use standalone -- but I am not sure if a
transaction manager exists which will do DS transactions around
hibernate transactions, etc?
Here is sample test case (with manually demarcated tx's for testing)
transactionManager is the HibernateTransactionManager and the
DataSource is just a DriverManagerDataSource
I have can happily throw a DataSourceTransactionManager into the mix,
but figure best to ask about ways to do this =)
public void testHibTxManagerSharesDSTxWithHib() throws Exception
{
final DefaultTransactionDefinition def = new
DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
final PlatformTransactionManager ptm =
(PlatformTransactionManager)
getContext().getBean("transactionManager");
final TransactionStatus status = ptm.getTransaction(def);
final IDBI dbi = (IDBI) getContext().getBean("dbi");
final Handle one = dbi.open();
final SessionFactory factory = (SessionFactory)
getContext().getBean("sessionFactory");
final Session sesion = factory.openSession();
one.execute("insert into batch_log (batch_id) values (87)");
assertFalse(one.getConnection().getAutoCommit());
final BatchLog log = (BatchLog) sesion.get(BatchLog.class, new
Long(87));
assertNotNull(log);
ptm.commit(status);
}
Thanks!
-Brian
|