Hi!
I'm trying to use 2 datasources on my project.
With one entityManager everything goes ok, but when I add a second one I get this Exception:
I've found a post about the problem. It states that a solution is to declaring an abstract bean:Code:org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
Here is the code of my first entity manager:Code:<bean id="abstractEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" abstract="true" />
And here the transaction managerCode:<bean id="emf" parent="abstractEntityManagerFactory"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> </property> <property name="packagesToScan" value="it.cpmapave.frigoristi.domain"/> <property name="jpaProperties"> <props> <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.hbm2ddl.auto">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">10</prop> <prop key="hibernate.show_sql">true</prop> <!-- Listeners for Hibernate Envers --> <prop key="hibernate.ejb.event.post-insert"> org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener </prop> <prop key="hibernate.ejb.event.post-update"> org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener </prop> <prop key="hibernate.ejb.event.post-delete"> org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener </prop> <prop key="hibernate.ejb.event.pre-collection-update"> org.hibernate.envers.event.AuditEventListener </prop> <prop key="hibernate.ejb.event.pre-collection-remove"> org.hibernate.envers.event.AuditEventListener </prop> <prop key="hibernate.ejb.event.post-collection-recreate"> org.hibernate.envers.event.AuditEventListener </prop> <!-- Properties for Hibernate Envers --> <prop key="org.hibernate.envers.audit_table_suffix">_H</prop> <prop key="org.hibernate.envers.revision_field_name">AUDIT_REVISION</prop> <prop key="org.hibernate.envers.revision_type_field_name">ACTION_TYPE</prop> <prop key="org.hibernate.envers.audit_strategy">org.hibernate.envers.strategy.ValidityAuditStrategy</prop> <prop key="org.hibernate.envers.audit_strategy_validity_end_rev_field_name">AUDIT_REVISION_END</prop> <prop key="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp">true</prop> <prop key="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name">AUDIT_REVISION_END_TS</prop> </props> </property>
..and the jpa repository:Code:<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="emf"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" />
Without specifying a second Entity Manager everything works.. but when I add these lines:Code:<jpa:repositories base-package="it.cpmapave.frigoristi.repository" entity-manager-factory-ref="emf" transaction-manager-ref="transactionManager"/> <jpa:auditing auditor-aware-ref="auditorAwareBean"/> <bean id="auditorAwareBean" class="it.cpmapave.frigoristi.auditor.AuditorAwareBean"/>
I got the exception.Code:<bean id="emf2" parent="abstractEntityManagerFactory"> ....
I've seen that other users have same issue.. but I can't find a solution.
Any help would be appreciated!
Marco


Reply With Quote
