Environment env = createEnvironment(context);
KnowledgeBase kbase = initializeKnowledgeBase(simpleRule);
StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
commandKSession.getId(); // initialize CSEM
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) commandKSession).getCommandService();
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);