I can not find the article, but I remember reading that in Hibernate 3, when you set up you hibernate.cfg.xml file with your transaction factory set to JTATransaction and your transaction manager set to Weblogic or JBoss etc, the session factory would automatically attach any Session you request to the current ongoing transaction.
Code:
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
If you can not have it to work, you can synchronize it yourself (which we did, but it's a lot of code) by implementing the javax.transaction.Synchronization interface and accessing your transaction manager with the following code:
Code:
private TransactionManager getTransactionManager()
{
return (( SessionFactoryImplementor ) factory).getTransactionManager();
}