multiple entity-transactions
thesourpuss Sep 29, 2009 9:45 AMHi,
i did a lot of research here in the user forum about transactions, but no one seams to have the same problem. I don't know if it is a bug or just an architectural problem.
The problem only occurs in test sources, because here I use the entity-transaction, whereas in productive I use ejb-transaction, which works normal.
Initial situation: I have 2 jar modules, each one has it's own persistence.xml and components.xml, as both of them have their own entities and access to database (same database).
Module 1 - component.xml:
<persistence:entity-manager-factory name="coreService.entityManagerFactory" class="org.jboss.seam.persistence.EntityManagerFactory" persistence-unit-name="CORE_SERVICE_HSQL_TEST_PERSISTENCE" precedence="10" /> <transaction:entity-transaction entity-manager="#{coreService.entityManager}" /> <persistence:managed-persistence-context name="coreService.entityManager" auto-create="true" precedence="10" entity-manager-factory="#{coreService.entityManagerFactory}" /> <component name="coreService.companyDao" class="com.core.service.dao.GenericDaoJpa" auto-create="true"> <property name="type">com.core.service.domain.Company</property> <property name="entityManager">#{coreService.entityManager}</property> </component> <component name="coreService.userDao" class="com.core.service.dao.GenericDaoJpa" auto-create="true"> <property name="type">com.core.service.domain.Users</property> <property name="entityManager">#{coreService.entityManager}</property> </component>
Module 2 - component.xml:
<persistence:entity-manager-factory name="coreWorkflow.entityManagerFactory" class="org.jboss.seam.persistence.EntityManagerFactory" persistence-unit-name="CORE_WORKFLOW_HSQL_TEST_PERSISTENCE" /> <persistence:managed-persistence-context name="coreWorkflow.entityManager" auto-create="true" precedence="10" entity-manager-factory="#{coreWorkflow.entityManagerFactory}" /> <transaction:entity-transaction name="coreWorkflow.transaction" entity-manager="#{coreWorkflow.entityManager}" /> <!-- Test DAO for TestUser Entity --> <component name="coreWorkflow.testUserDao" class="com.core.service.dao.GenericDaoJpa" auto-create="true"> <property name="type">com.core.workflow.domain.TestUser</property> <property name="entityManager">#{coreWorkflow.entityManager}</property> </component>
As you see the Module 2 -component.xml has a named entity-transaction tag in it, which referes to the local coreWorkflow.entityManager. And here is the problem:
If I give both transaction:entity-transaction tags a name an error at @Transactional method processesing - in class Work - occurs, because the class Work tries to get the instance of a transaction by type and not by name. So in the second module it always tries to get a transaction instance with the unnamed entity-transaction declaration from Module 1. This is the coreService.entityManager.
Can anybody tell me how to avoid that the class Work takes the default transaction (getInstance(Transaction.class,...)). It should take the named entity-transaction declaration from module2 - component.xml, where entity-manager is coreWorkflow.entityManager.
Thanks in advance,
Tony