Здравствуйте. Как указать имя конкретного EntityManagerFactory при использовании @PersistenceContext?
Такой код:
@PersistenceContext
private EntityManager em;
И код инициализации бинов:
// ----- ADM ------
@Bean(name = "dataSourceNsi")
public DataSource dataSourceAdm() throws NamingException {
return (DataSource) new JndiTemplate().lookup("java:comp/env/" + admJndiName);
}
@Bean(name = Constants.ADM_ENTITY_MANAGER_FACTORY_NAME, destroyMethod = "")
public LocalContainerEntityManagerFactoryBean admEntityManagerFactory() throws NamingException {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSourceAdm());
em.setPackagesToScan(admPackagesToScan);
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(hibernatePropertiesAdm());
return em;
}
@Bean(name = Constants.ADM_TRANSACTION_MANAGER_NAME, destroyMethod = "")
public PlatformTransactionManager admTransactionManager() throws NamingException {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(admEntityManagerFactory().getObject());
return transactionManager;
}