Announcement Announcement Module
Collapse
No announcement yet.
Spring with multiple LocalContainerEntityManagerFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring with multiple LocalContainerEntityManagerFactoryBean

    Hi guys,

    I've problem with multiple entitymanagerfactory jpa configuration, please anyone help me to fix this config??


    Code:
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
        <context:annotation-config/>
    
        <aop:aspectj-autoproxy/>
    
        <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
    
        <bean id="jpaVendorAdapterMySql" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
            <property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
            <!--<property name="databasePlatform" value="org.eclipse.persistence.platform.database.HSQLPlatform"/>-->
            <!--<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform"/>-->
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true"/>
        </bean>
    
        <bean id="jpaVendorAdapterOracle" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
            <!--<property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>-->
            <!--<property name="databasePlatform" value="org.eclipse.persistence.platform.database.HSQLPlatform"/>-->
            <property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform"/>
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="true"/>
        </bean>
    
    
    
        <bean id="mySqlEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="jpaVendorAdapter" ref="jpaVendorAdapterMySql"/>
            <property name="jpaDialect" ref="jpaDialect"/>
            <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-MySql.xml" />
            <property name="persistenceUnitName" value="mySqlUnit" />
            <property name="dataSource" ref="ds_MySql" />
        </bean>
    
        <bean id="oracleEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="jpaVendorAdapter" ref="jpaVendorAdapterOracle"/>
            <property name="jpaDialect" ref="jpaDialect"/>
            <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-Oracle.xml" />
            <property name="persistenceUnitName" value="oracleUnit" />
            <property name="dataSource" ref="ds_Oracle" />
        </bean>
    
        <bean id="tmOracle" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="oracleEMF"/>
            <property name="jpaDialect" ref="jpaDialect"/>
        </bean>
    
        <bean id="tmMySql" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="mySqlEMF"/>
            <property name="jpaDialect" ref="jpaDialect"/>
        </bean>
    
        <tx:annotation-driven transaction-manager="tmMySql"/>
    
        <tx:annotation-driven transaction-manager="tmOracle"/>
    
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
        <bean id="ds_Oracle" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
            <property name="jdbcUrl" value="jdbc:oracle:thin:@//10.255.20.115:1521/support" />
            <property name="user" value="SECURPT" />
            <property name="password" value="securreport" />
            <!--<property name="acquireIncrement" value="${pool.acquireIncrement}" />-->
            <!--<property name="maxPoolSize" value="${pool.maxPoolSize}" />-->
            <!--<property name="minPoolSize" value="${pool.minPoolSize}" />-->
            <!--<property name="idleConnectionTestPeriod" value="${pool.idleConnectionTestPeriod}" />-->
        </bean>
    
        <bean id="ds_MySql" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="com.mysql.jdbc.Driver" />
            <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ctidb?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf-8&amp;amp;autoReconnect=true" />
            <property name="user" value="root" />
            <property name="password" value="root" />
            <!--<property name="acquireIncrement" value="${pool.acquireIncrement}" />-->
            <!--<property name="maxPoolSize" value="${pool.maxPoolSize}" />-->
            <!--<property name="minPoolSize" value="${pool.minPoolSize}" />-->
            <!--<property name="idleConnectionTestPeriod" value="${pool.idleConnectionTestPeriod}" />-->
        </bean>
    </beans>

  • #2
    @ayok7


    A solution to this issue is posted in my article @ http://viralpatel.net/blogs/2011/01/...iguration.html

    I hope it helps you.

    B.Roogards
    jD @ http://pragmatikroo.blogspot.com

    Comment

    Working...
    X