Persistence Units and Persistence Contexts in java

Chapter 7 - Persistence Units and Persistence Contexts

    Persistence Units and Persistence Contexts in java

  •           The presence of @PersistenceContext or @PersistenceUnit annotations in Spring may cause deployment errors when the persistence.xml has been renamed.The persistence.xml may be renamed in order to use a Spring-based EntityManagerFactory.

              The @PersistenceContext and @PersistenceUnit annotations are used for supporting the container-driver injection of container-managed persistence contexts and persistence units, respectively.

              This can be resolved either by disabling the scanning of deployment classes, or by using the @Autowire injection. The Metadata-complete Flag Can Be Used to Disable Class Scanning.

     < web-app version="2.5" xmlns=""
    metadata-complete="true" >

              An alternative is to use @Autowired instead of@PersistenceUnit/@PersistenceContext. In the case of @PersistenceUnit/EntityManagerFactory injection.

    Using a SharedEntityManager Bean to Create an Injectable Transaction-aware EntityManager :

    < bean id="entityManagerWrapper" class="" >
       < property name="entityManagerFactory" ref="entityManagerFactory"/ >
    < /bean >

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy