I'm successfully using JPA (Jboss 4.2 / Hibernate) within EJB 2.1 Stateless, retrieving Entity Manager Factory from Jndi (published using persistence.xml jboss.entity.manager.factory.jndi.name property).
When switching to Spring Entity Manager injection, in order to get it work in websphere, I'm getting "java.lang.IllegalArgumentException : Removing a detached instance" when performing:
MyEntity entity = aDao.read(pKey);
aDao.delete(entity);
This make me think that Spring is not reusing the JTA transaction and is creating one transaction to read the entity, and another to delete the entity.
My spring configuration is:
<jee:jndi-lookup id="dataSource" resource-ref="true" jndi-name="java:OracleDSxa" />
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
<tx:jta-transaction-manager />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="mypersistenceunit" />
</bean>
Is there anything wrong with the Spring configuration ? When I instanciate the EntityManagerFactory myself as a singleton it is working, is it an appropriate solution and why isn't it working with the Spring one ?
I tried without (re)defining the entity manager factory, but then injection fail and I get No bean named 'mypersistenceunit'
Thank you for any pointer
Edit 1: Here is my persistence xml configuration for hibernate:
<property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.connection.release_mode" value="auto" />
<property name="hibernate.current_session_context_class" value="jta" />
<property name="hibernate.transaction.flush_before_completion" value="true" />
<property name="hibernate.transaction.auto_close_session" value="false" />
Edit 2: Transaction is managed by the container (CMB EJB 2.1 Stateless), which is working under Jboss using Entity Manager from Jndi
Edit 3: Making usage of jndi resource name referenced in the EJB 2.1 Session, jee:jndi-lookup id="dataSource" resource-ref="true" jndi-name="jdbc/myDataSourceRef" , did not solve the problem.
Edit 4: Hibernate version is 3.2.1.ga, provided by Jboss as JPA implementation