|Re: [eclipselink-users] persistence.xml in standalone app and enterprise beans|
That is standard practice for a container managed (transaction-type="JTA" (default on EE) and @PersistenceContext(.. PersistenceContextType.TRANSACTION (default on EE)) persistence unit on a @Stateless session bean - all in the ejb.jar along with the persistence.xml. The entities themselves can be packaged with the ejb.jar or a separate entities.jar - however normally persistence.xml stays with the session bean package root or ejbModule - I have not verified if the persistence.xml can run if packaged with the entities.jar (likely not as it would not be sharable among CM and application managed PU's (via @PersistenceUnit) running both separately on the ejb and web container.
Then the @EJB (SSB above with the dependency injected PU) is injected on the client - usually a servlet or other controller. If you are running purely container managed transactions for your entity operations via your session bean then the war should have no knowledge of the JPA layer - so no persistence.xml in the war.
If by enterprise bean you mean @Entity with no @Stateless or @Stateful enterprise (session bean) managing persistence - then you place your persistence.xml inside the WAR along with the entities defined in the war or in an entities.jar packaged with the war (instead of the EAR) above.
There is a 3rd scenario where you can use @PersistenceContext injection on a servlet in the war and the EJB container classloader will run with the container managed entityManager as opposed to a @PersistenceUnit application managed EntityManagerFactory - in that case persistence.xml should be with the entities in the war or with the entities.jar in the EAR app-inf/lib or EAR root - I just need to verify this scenario first before signing off on it.
If you post your DI setup and architecture if it is different - we can try out different scenarios - I have not tried a @Stateful session bean lateley.
There may be differences (scope/concurrency) for applications using standard DI (dependency injection) or JNDI lookups (manually or via container specific XML configurations in the ear/ejb/war)
Check out the one standard @Stateless/@PersistenceUnit/@EJB tutorial architecture below.
Michael Simons wrote: