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="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    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="org.springframework.orm.jpa.support.SharedEntityManagerBean" >
       < 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