Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Multiple Persistence Unit bug
    text
    copied!<p>I'm trying to add one more database/schema/persistenceUnit in my project and I'm receiving the error:</p> <p><code> No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2 </code></p> <p>I google/api allot and could not found why spring is complaining about my configuration. <br><br> Here is part of my applicationContext.xml</p> <p><code></p> <pre><code> &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="transactionManager" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="${show.hibernate.sql}" /&gt; &lt;property name="generateDdl" value="false" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="${database.driver}" /&gt; &lt;property name="url" ... &lt;property name="testOnBorrow" value="true" /&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;bean id="entityManagerFactoryREST" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSourceREST" /&gt; &lt;property name="persistenceUnitName" value="REST" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="${show.hibernate.sql}" /&gt; &lt;property name="generateDdl" value="false" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="dataSourceREST" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName" value="${database.driver}" /&gt; ... &lt;property name="testOnBorrow" value="true" /&gt; &lt;/bean&gt; &lt;bean id="transactionManagerREST" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactoryREST" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="REST"/&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; </code></pre> <p></code></p> <hr> <p>Some questions:</p> <ul> <li>Do I need to have two <strong>tx:annotation-driven</strong> ?</li> <li>Do I need to specify <strong>persistenceUnitName</strong> in the factory ?</li> </ul> <p>I'm putting some notes of my digg in spring forum (<a href="http://forum.springsource.org/showthread.php?p=273072#post273072" rel="noreferrer">LINK</a>)</p> <p>Well thats it... any help will be glad!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload