added multi persistence unit support
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package de.muehlencord.shared.account.web;
|
||||
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Disposes;
|
||||
@ -17,26 +18,27 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class PersistenceContextFactory {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceContextFactory.class);
|
||||
|
||||
@PersistenceUnit
|
||||
|
||||
@PersistenceUnit (unitName = "accountPu")
|
||||
EntityManagerFactory emf;
|
||||
|
||||
|
||||
@Produces
|
||||
@AccountPU
|
||||
@RequestScoped
|
||||
public EntityManager getEntityManager() {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("getting entityManager");
|
||||
}
|
||||
LOGGER.trace("getting entityManager for accountPu");
|
||||
}
|
||||
return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
|
||||
}
|
||||
|
||||
public void closeEntityManager (@Disposes EntityManager em) {
|
||||
|
||||
public void closeEntityManager(@Disposes EntityManager em) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("closing entityManager");
|
||||
}
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="de.muehlencord.shared.accountUiPu" transaction-type="JTA">
|
||||
<persistence-unit name="accountPu" transaction-type="JTA">
|
||||
<jta-data-source>java:/jboss/accountDs</jta-data-source>
|
||||
<class>de.muehlencord.shared.account.business.account.entity.AccountEntity</class>
|
||||
<class>de.muehlencord.shared.account.business.account.entity.AccountHistoryEntity</class>
|
||||
|
||||
Reference in New Issue
Block a user