Hi Martin,

I think that em.persist only updates the entity context (hibernate session). The DB is updated only after you commit transaction. So it looks like the transactions are not being committed in your case. That would be my guess.

Best regards
Michal


On Tue, Aug 4, 2009 at 9:14 AM, Ševčík Martin <MaSevcik@cpoj.cz> wrote:
I have a simple flow with human task and I want to persist it into database. I'm using MSSQL DB.

My code is like this:

               KnowledgeBase kbase = readKnowledgeBase();
                       // create the entity manager factory and register it in the environment
                       EntityManagerFactory emf =
                           Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );
                       Environment env = KnowledgeBaseFactory.newEnvironment();
                       env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
                       BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager();
                       env.set( EnvironmentName.TRANSACTION_MANAGER, btm);

                       StatefulKnowledgeSession ksession =
                           JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );

                       KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
                       ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
                       // start a new process instance
                       Map<String,Object> data = new HashMap<String,Object>();
                       data.put("data3", new MyTask(1,"This is taks 1"));
                       ProcessInstance pi = ksession.startProcess("com.sample.ruleflow",data);
                       logger.close();

But when i run it, it end up with this error and there is nothing in the database (the tables were created, but there are all empty):

java.lang.NullPointerException
       at org.drools.persistence.processinstance.ProcessInstanceInfo.getId(ProcessInstanceInfo.java:70)
       at org.drools.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:34)
       at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1620)
       at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:46)
       at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:10)
       at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:229)
       at org.drools.process.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:163)
       at com.sample.RuleFlowPersistenceTest.main(RuleFlowPersistenceTest.java:74)
java.lang.RuntimeException: Could not rollback transaction
       at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:258)
       at org.drools.process.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:163)
       at com.sample.RuleFlowPersistenceTest.main(RuleFlowPersistenceTest.java:74)
Caused by: java.lang.RuntimeException: Could not execute command
       at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:255)
       ... 2 more
Caused by: java.lang.NullPointerException
       at org.drools.persistence.processinstance.ProcessInstanceInfo.getId(ProcessInstanceInfo.java:70)
       at org.drools.persistence.processinstance.JPAProcessInstanceManager.addProcessInstance(JPAProcessInstanceManager.java:34)
       at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1620)
       at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:46)
       at org.drools.process.command.StartProcessCommand.execute(StartProcessCommand.java:10)
       at org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:229)
       ... 2 more

In JPAProcessInstanceManager.java there this method is called:

   public void addProcessInstance(ProcessInstance processInstance) {
       ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo( processInstance );
       EntityManager em = (EntityManager) this.workingMemory.getEnvironment().get( EnvironmentName.ENTITY_MANAGER );
       em.persist( processInstanceInfo );
       ((ProcessInstance) processInstance).setId( processInstanceInfo.getId() );
       processInstanceInfo.updateLastReadDate();
       internalAddProcessInstance(processInstance);
   }


But em.persist does nothing, no connection do DB is called. And then the  next line will fail.




Can anybody help me.

Thanks

Martin Sevcik

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users