Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] persistence.xml in standalone app and enterprise beans

Michael,
    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.
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial#Create_J2EE_application

    thank you
    /Michael O'Brien
    http://www.eclipselink.org

Michael Simons wrote:

Hi,

 

Please, can anybody tell me how to get an enterprise bean to work with the persistence.xml in a jar.

In my standalone application it works well, but in EJBs the only place EL finds the persistence.xml seems to be in the META-INF folder in the bean jar-file itself.

Any hints what I might be missing would be appreciated.

 

Kind Regards, Michael


_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top