[rules-users] Exception Thrown When Dispose KSession in JPA Persistence Environment

Rui Tang tangrui at zyeeda.com
Sun Nov 14 11:12:30 EST 2010


Hi list,

I have a simple program using drools-persistence-jpa library.

StatefulKnowledgeSession session = null;
try {
    ksession = JPAKnowledgeService.newStatefulKnowledgeSession(this.kbase,
null, env);
    ksession.execute(myCustomCommand);
} finally {
    if (ksession != null) {
        ksession.dispose();
    }
}

if ksession.execute statement throws an exception, then ksession.dispose
statement will throw another fancy exception like this:

java.lang.RuntimeException: Could not find session data for id 473
    at
org.drools.persistence.session.SingleSessionCommandService.initKsession(SingleSessionCommandService.java:183)
    at
org.drools.persistence.session.SingleSessionCommandService.execute(SingleSessionCommandService.java:272)

My environment is like following:

1. I use JTA to manage tx across several sessions.
2. I set a global EntityManagerFactory, TransactionFactory and a
UserTransaction to the env variable when initialize the ksession.

I think this exception occurred because of this:

When I execute my custom command, a user tx is opened, but when exception
occurs, this tx is rolled back. But in ksession.dispose statement, it will
use the uncommited session id to retrieve the persisted ksession, then
exception is thrown.

My questing is that, do I really need to put ksession.dispose in the finally
block to force the ksession to dispose even when exception occurred. If not
won't that matter? If yes how to deal with the exception, add another
try/catch block around the ksession.dispose statement?

Thank you in advance.

-- 
唐睿
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101115/d8a5ade2/attachment.html 


More information about the rules-users mailing list