Skip to content

entityManagerFactory  #1

Description

@afattahi54

I used this code but set the entityManagerFactory as mentioned in for spring 5

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx.xsd
	  http://www.springframework.org/schema/jee       http://www.springframework.org/schema/jee/spring-jee.xsd
	  http://www.springframework.org/schema/data/jpa  http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

   <jpa:repositories base-package="net.iranet.isc.saba.persistence.repository" />
   	
   <!-- This will ensure that hibernate or jpa exceptions are automatically translated into
    Spring's generic DataAccessException hierarchy for those classes annotated with Repository
    For example see PersonDaoJpa-->
   <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
   
   <bean id="entityManagerFactory"
     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
     
     <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
     <property name="packagesToScan" value="net.iranet.isc.saba.persistence" />
     <property name="dataSource" ref="dataSource" />
     
    </bean>
      
   <jee:jndi-lookup id="dataSource" jndi-name="jdbc/SABA"/>
   
   <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
   
    <!-- bean post-processor for JPA annotations -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

	<!-- Transaction Config --> 
   <bean id="transactionManager"  class="org.springframework.orm.jpa.JpaTransactionManager"
   		p:entityManagerFactory-ref="entityManagerFactory" />
   
   <!-- use declarative transaction management  -->
   <tx:annotation-driven transaction-manager="transactionManager"/>

 
</beans>

and persistence.xml as:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence.xsd"
             version="2.0">
    <!--  No need to specify the provider as we already have specified JPA vendor in applicationContext.xml -->
    <persistence-unit name="springJpaPersistenceUnit" />
</persistence>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions