Seam and transaction management
shavo26 Jun 9, 2010 8:29 PMEnvironment:
Seam 2.2.0.GA
JDK 1.6
JBOSS 5.1.0.GA
Hibernate 3.3.0.GA
I have a question concerning transaction management. In my seam project i am using EJB 3 stateful session beans for business logic and behind the scenes JSF action classes. Also using JPA/Hibernate for ORM persistence entities.
In components.xml i had a problem with seam generated file involving looking up entity manager:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="@puJndiName@"/>
I found solution to this problem on this forum changing to:
<transaction:entity-transaction entity-manager="#{entityManager}"/> <persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/EbusinessHibernateEntityManagerFactory"/>
and removing
<persistence-unit-ref>
element from web.xml
In my persistence.xml transaction-type was JTA and hibernate property set was
<property name="jboss.entity.manager.factory.jndi.name" value="java:/ebusinessEntityManagerFactory"/>
First question is if i deploy now on weblogic/websphere or some other certified JEE5 app server how should i lookup entity manager, will this property still work even though it is specifically for jboss or do i have to change it to:
<persistence:entity-manager-factory name="ebusiness" /> <persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{ebusiness}" />
where ebusiness is the name of my persistence unit?
Second question is in relation to transaction type. This element
<transaction:entity-transaction entity-manager="#{entityManager}"/>
means that im using JPA transactions and becuase i have set transaction type as default JTA in persistence.xml i will get an exception java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
Fix is to set the transaction type to
"RESOURCE_LOCAL"
. But what is the implications of this change?
It states in jpa api doc that
A container-managed entity manager must be a JTA entity manager.JTA entity manager transactions are started and ended outside of the entity manager, and the entity manager methods share the transaction context of the session bean methods that invoke them.
So if i want my entity manager container managed i should not have this element
<transaction:entity-transaction entity-manager="#{entityManager}"/>
set in components.xml and set property
hibernate.transaction.manager_lookup_class
appropriately in persistence.xml?
Cheers,
Shane.