|
From: Brian M. <br...@ch...> - 2004-12-16 15:58:42
|
Abort, Rob Butler helped me figure this out =)
Spring Tx management rocks!
-Brian
On Dec 16, 2004, at 10:23 AM, Brian McCallister wrote:
> 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
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real
> users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|