Skip to content

Instantly share code, notes, and snippets.

@teabot
Created January 17, 2013 13:21
Show Gist options
  • Save teabot/4555896 to your computer and use it in GitHub Desktop.
Save teabot/4555896 to your computer and use it in GitHub Desktop.
A Hibernate org.hibernate.transaction.JTATransactionFactory implementation that avoids using JNDI for lookups.
package my.project.hibernate;
import javax.transaction.UserTransaction;
import org.hibernate.transaction.JTATransactionFactory;
/**
* A Hibernate {@link JTATransactionFactory} implementation that avoids using JNDI for lookups. You must set the
* {@link UserTransaction} on this bean with #setUserTransaction(UserTransaction)} before using it.
*/
public class LocalJtaTransactionFactory extends JTATransactionFactory {
private static volatile UserTransaction userTransaction;
public synchronized void setUserTransaction(UserTransaction userTransaction) {
LocalJtaTransactionFactory.userTransaction = userTransaction;
}
@Override
protected UserTransaction getUserTransaction() {
return userTransaction;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment