use of org.drools.persistence.jpa.JpaPersistenceContextManager in project drools by kiegroup.
the class JtaTransactionManagerTest method testSingleSessionCommandServiceAndJtaTransactionManagerTogether.
@Test
public void testSingleSessionCommandServiceAndJtaTransactionManagerTogether() throws Exception {
// Initialize drools environment stuff
Environment env = createEnvironment(context);
KieBase kbase = initializeKnowledgeBase(simpleRule);
KieSession commandKSession = KieServices.get().getStoreServices().newKieSession(kbase, null, env);
// StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
// initialize CSEM
commandKSession.getIdentifier();
PersistableRunner commandService = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) commandKSession).getRunner();
JpaPersistenceContextManager jpm = (JpaPersistenceContextManager) getValueOfField("jpm", commandService);
TransactionTestObject mainObject = new TransactionTestObject();
mainObject.setName("mainCommand");
TransactionTestObject subObject = new TransactionTestObject();
subObject.setName("subCommand");
mainObject.setSubObject(subObject);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
HashMap<String, Object> emEnv = new HashMap<String, Object>();
emEnv.put(COMMAND_ENTITY_MANAGER_FACTORY, emf);
emEnv.put(COMMAND_ENTITY_MANAGER, jpm.getCommandScopedEntityManager());
TransactionTestCommand txTestCmd = new TransactionTestCommand(mainObject, subObject, emEnv);
commandKSession.execute(txTestCmd);
ut.commit();
}
Aggregations