Hi list,<br><br>I have a simple program using drools-persistence-jpa library.<br><br>StatefulKnowledgeSession session = null;<br>try {<br>    ksession = JPAKnowledgeService.newStatefulKnowledgeSession(this.kbase, null, env);<br>

    ksession.execute(myCustomCommand);<br>} finally {<br>    if (ksession != null) {<br>        ksession.dispose();<br>    }<br>}<br><br>if ksession.execute statement throws an exception, then ksession.dispose statement will throw another fancy exception like this:<br>

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

<br>My environment is like following:<br><br>1. I use JTA to manage tx across several sessions.<br>2. I set a global EntityManagerFactory, TransactionFactory and a UserTransaction to the env variable when initialize the ksession.<br>

<br>I think this exception occurred because of this:<br><br>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.<br>

<br>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&#39;t that matter? If yes how to deal with the exception, add another try/catch block around the ksession.dispose statement?<br>

<br>Thank you in advance.<br clear="all"><br>-- <br>唐睿<br>