I learnt that java:comp/UserTransaction is not available for non EE threads in Jboss 7.x. I have non EE threads in my application that is calling java:comp/UserTransaction by default, please how do I change this default value to java:jboss/UserTransaction? I need help please..
2 Answers
If you have a Hibernate configuration file, e.g. hibernate.cfg.xml
, you can add this property:
<property name="jta.UserTransaction">java:jboss/UserTransaction</property>
I found it in this document and it works for me. Your hibernate.cfg.xml
file should look like something like this:
<hibernate-configuration>
<session-factory>
...
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="jta.UserTransaction">java:jboss/UserTransaction</property>
...
</session-factory>
</hibernate-configuration>

- 1,453
- 2
- 16
- 32
For Java EE 6 and lower it's best to not create threads inside your application because as you can see you lose context. In Java EE 7 however you can use the new ManagedExecutorService
. This is available in WildFly, but not JBoss AS 7.x.
You can inject the ManagedExecutorService
with @Resource
as well.
If it's not an option to use WildFly the only way to do it would be to some how copy it over before you launch the new thread. Though that could be rather dangerous as the transaction is meant to be managed by the container and you're using it outside the container.

- 16,800
- 44
- 60