diff --git a/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/AbstractJtaPlatform.java b/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/AbstractJtaPlatform.java index c05e261b3d..fdef6043de 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/AbstractJtaPlatform.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/AbstractJtaPlatform.java @@ -67,8 +67,24 @@ public abstract class AbstractJtaPlatform protected abstract UserTransaction locateUserTransaction(); public void configure(Map configValues) { - cacheTransactionManager = ConfigurationHelper.getBoolean( AvailableSettings.JTA_CACHE_TM, configValues, true ); - cacheUserTransaction = ConfigurationHelper.getBoolean( AvailableSettings.JTA_CACHE_UT, configValues, false ); + cacheTransactionManager = ConfigurationHelper.getBoolean( + AvailableSettings.JTA_CACHE_TM, + configValues, + canCacheTransactionManagerByDefault() + ); + cacheUserTransaction = ConfigurationHelper.getBoolean( + AvailableSettings.JTA_CACHE_UT, + configValues, + canCacheUserTransactionByDefault() + ); + } + + protected boolean canCacheTransactionManagerByDefault() { + return true; + } + + protected boolean canCacheUserTransactionByDefault() { + return false; } protected boolean canCacheTransactionManager() { diff --git a/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/JBossAppServerJtaPlatform.java b/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/JBossAppServerJtaPlatform.java index 92bef427a8..8ea39a1649 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/JBossAppServerJtaPlatform.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jta/platform/internal/JBossAppServerJtaPlatform.java @@ -36,25 +36,46 @@ import org.hibernate.service.jndi.JndiException; public class JBossAppServerJtaPlatform extends AbstractJtaPlatform { public static final String AS7_TM_NAME = "java:jboss/TransactionManager"; public static final String AS4_TM_NAME = "java:/TransactionManager"; - public static final String UT_NAME = "java:comp/UserTransaction"; // should work with AS7 and earlier + public static final String JBOSS__UT_NAME = "java:jboss/UserTransaction"; + public static final String UT_NAME = "java:comp/UserTransaction"; + + @Override + protected boolean canCacheUserTransactionByDefault() { + return true; + } + + @Override + protected boolean canCacheTransactionManagerByDefault() { + return true; + } @Override protected TransactionManager locateTransactionManager() { try { - return (TransactionManager) jndiService().locate(AS7_TM_NAME); + return (TransactionManager) jndiService().locate( AS7_TM_NAME ); } - catch(JndiException jndiException) { + catch (JndiException jndiException) { try { - return (TransactionManager) jndiService().locate(AS4_TM_NAME); + return (TransactionManager) jndiService().locate( AS4_TM_NAME ); } - catch(JndiException jndiExceptionInner) { - throw new JndiException("unable to find transaction manager", jndiException); + catch (JndiException jndiExceptionInner) { + throw new JndiException( "unable to find transaction manager", jndiException ); } } } @Override protected UserTransaction locateUserTransaction() { - return (UserTransaction) jndiService().locate( UT_NAME ); + try { + return (UserTransaction) jndiService().locate( JBOSS__UT_NAME ); + } + catch (JndiException jndiException) { + try { + return (UserTransaction) jndiService().locate( UT_NAME ); + } + catch (JndiException jndiExceptionInner) { + throw new JndiException( "unable to find UserTransaction", jndiException ); + } + } } }