0

I have two data sources with different PlatformTransactionManager, LocalContainerEntityManagerFactoryBean

I have RoutingDataSource class which extends org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource to route right data source for each PlatformTransactionManager.

I have annoated manager method with org.springframework.transaction.annotation.Transactional as @Transactional(value="reportingDatasource")

I have javax.persistence.EntityManager declaration in my Repository to execute some queries.

That EntityManager declaration expects PersistenceContext with unitName as mentioned below to identify different Datasource. Is there any way to use one EntityManager declaration where Transactional will route to expected data source based on the value specified

@PersistenceContext(unitName="master") private EntityManager em;

@PersistenceContext(unitName="reporing") private EntityManager reportEm;

If i didn't specify unitName it is throwing this error "No qualifying bean of type 'javax.persistence.EntityManagerFactory' available: expected single matching bean but found 2"

Alex
  • 21
  • 3

1 Answers1