I am trying to figure out if a persistence-unit has to be packaged as an EJB. What I have is an ear application that I want to deploy to JBoss. This application contains a jar containing my domain entities. This jar contains the following persistence unit which specifies a jta-data-source:
Code:
<persistence-unit name="myappDatabase">
<jta-data-source>java:/myappDatasource</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/myappEntityManagerFactory"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
</properties>
</persistence-unit>
If I package the jar as a normal jar, I get the following exception when JBoss tries to deploy the application:
Code:
javax.naming.NameNotFoundException: myappEntityManagerFactory not bound
If I package my domain entities as an ejb jar, the exception goes away. So I have two questions:
1) Is it true that if I have a persistence-unit that needs to be deployed on JBoss then it must be packaged as an ejb?
2) How do I test this jar outside an ejb container (using junit etc.)? I am able to do this by changing the persistence configuration to transaction-type="RESOURCE_LOCAL", but then I can't keep both the configurations in the same jar (local and jta). How do people deal with this issue?
Thanks.
Naresh