Discussion:
[jboss-user] [jBPM] - Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed
Maciej Swiderski
2012-06-29 17:42:35 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/745100#745100

--------------------------------------------------------------
the issue is that you dispose the session before transaction is completed which cause the mentioned error. Make sure that the dispose will happen after transaction completion.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/745100#745100]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Pedro Gonçalves
2012-07-03 10:11:07 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/745700#745700

--------------------------------------------------------------
Once again, thanks Maciej ;)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/745700#745700]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Miloud Haimoune
2012-07-12 13:54:47 UTC
Permalink
Miloud Haimoune [https://community.jboss.org/people/milhaim] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/747763#747763

--------------------------------------------------------------
Hi,

I'm facing the same issue :  java.lang.IllegalStateException: Illegal method call. This session was previously disposed. when I call session.dispose ().

How did you manage to solve it ?

in my case I have one running ksession where I have all my process instances.

In my application I have I button where I call the dispose  methode, this same methode was working with JBPM 5.2.

Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/747763#747763]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Miloud Haimoune
2012-07-12 13:57:15 UTC
Permalink
Miloud Haimoune [https://community.jboss.org/people/milhaim] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/747764#747764

--------------------------------------------------------------
here the  exception trace :

Caused by: java.lang.IllegalStateException: Illegal method call. This session was previously disposed.
    at org.drools.reteoo.DisposedReteooWorkingMemory.getSessionClock(DisposedReteooWorkingMemory.java:398)
    at org.drools.impl.StatefulKnowledgeSessionImpl.getSessionClock(StatefulKnowledgeSessionImpl.java:256)
    at org.drools.marshalling.impl.ProtobufMarshaller.marshall(ProtobufMarshaller.java:151)
    at org.drools.persistence.SessionMarshallingHelper.getSnapshot(SessionMarshallingHelper.java:72)
    at org.drools.persistence.info.SessionInfo.update(SessionInfo.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:23)
    at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:80)
    at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:65)
    at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:41)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:330)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:270)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/747764#747764]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Pedro Gonçalves
2012-07-12 16:56:52 UTC
Permalink
Pedro Gonçalves [https://community.jboss.org/people/pgoncalves] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/747829#747829

--------------------------------------------------------------
I can't say that I resolved the problem... I've just realized that I just postpone the error. But I'm still trying to understand it.

The solution for that problem is what Maciej said: the dispose is being done before the transaction end. Try to do it after the transaction end.

I've never worked with jbpm 5.2, but I'm thinking in give it a try, as I'm having some strange problems in 5.3 (which I'm currently investigating if the problem is my app or the jbpm5.3).
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/747829#747829]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Chris Johnson
2012-07-12 17:49:24 UTC
Permalink
Chris Johnson [https://community.jboss.org/people/cljackhammer] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/747839#747839

--------------------------------------------------------------
We need a response for this problem. I am having the same issue and it is delaying UAT testing.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/747839#747839]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2012-07-13 16:27:29 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/748083#748083

--------------------------------------------------------------
Guys, this really depends on how you use jbpm so there can't be single answer that fits all. So if you provide bit more details about your application design maybe we could help out.

Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/748083#748083]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Chris Johnson
2012-07-14 10:35:11 UTC
Permalink
Chris Johnson [https://community.jboss.org/people/cljackhammer] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/748121#748121

--------------------------------------------------------------
I am using the LocalTaskService and here is the sequence of events that causes the problem.

1) My client starts a process then disposes the session.
2) My client loads the session that was disposed in step 1 and  claims the first task in the process.
3) My client loads the session that was disposed in step 1 and  starts the first task in the process.
*4) My client loads the session that was disposed in step 1 and  completes the first task in the process and JBPM throws the following exception:*

*Caused by: java.lang.IllegalStateException: Illegal method call. This session was previously disposed.
    at org.drools.reteoo.DisposedReteooWorkingMemory.getSessionClock(DisposedReteooWorkingMemory.java:398)
    at org.drools.impl.StatefulKnowledgeSessionImpl.getSessionClock(StatefulKnowledgeSessionImpl.java:256)
    at org.drools.marshalling.impl.ProtobufMarshaller.marshall(ProtobufMarshaller.java:151)
    at org.drools.persistence.SessionMarshallingHelper.getSnapshot(SessionMarshallingHelper.java:72)
    at org.drools.persistence.info.SessionInfo.update(SessionInfo.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.hibernate.ejb.event.BeanCallback.invoke(BeanCallback.java:23)
    at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:80)
    at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:65)
    at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:41)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:330)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:270)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)*
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/748121#748121]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2012-07-15 18:50:49 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/748155#748155

--------------------------------------------------------------
Chris, could you prepare simple test case that illustrates that? That would give me a quick start to investigate the case and try to come up with some solutions for you.

Cheers
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/748155#748155]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
lyman liu
2012-11-14 06:57:34 UTC
Permalink
lyman liu [https://community.jboss.org/people/lymxiang] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/776351#776351

--------------------------------------------------------------
*Can you  help me   how to reload  the session that was disposed in step 1 ?*


in my application ,I have disposed the session, and I'm using persistent sessions, how can I reload it from the database using JPAKnowledgeService class BEFORE completing the task ?
I work hard to try reload,but I failed,I don't know how to do it. :-/

Please help ,thanks very much!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/776351#776351]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
sreeramk82
2012-11-14 07:06:26 UTC
Permalink
sreeramk82 [https://community.jboss.org/people/sreeramk82] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/776353#776353

--------------------------------------------------------------
EntityManagerFactory emf =
                    Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
                Environment env = EnvironmentFactory.newEnvironment();
                env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
                env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
                ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);


Try this
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/776353#776353]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
lyman liu
2012-11-27 01:57:24 UTC
Permalink
lyman liu [https://community.jboss.org/people/lymxiang] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/778457#778457

--------------------------------------------------------------
It's right ,thanks a lot
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/778457#778457]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Brian Wallis
2012-07-15 06:22:42 UTC
Permalink
Brian Wallis [https://community.jboss.org/people/bwallis42] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/748137#748137

--------------------------------------------------------------
I have the same problem where I am getting a session from within an onMessage() method of an Message Driven Bean. The transactions are container controlled so I cannot call the ksession dispose after the transaction ends since the container ends the transaction not me.

This was working with JBPM 5.1.


@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
    public void onMessage(Message message)
    {
        try
        {
            DocumentCreated inbound = MessageBusUtility.unmarshallMessage(message);
            LOGGER.info("Message body: " + inbound);


            ksession = jbpmLauncher.getSession();


            // start a new process instance
            Map<String, Object> params = buildParams(inbound);
            ksession.startProcess("au.com.infomedix.harvey." + inbound.getDocumentGroup().getWorkflowName().toLowerCase(), params);
            Audit.newWorkflow((String) params.get(EReferralFields.PATIENT_URNO.getKey()), (String) params.get(EReferralFields.PATIENT_DOMAIN.getKey()),
                    (String) params.get(EReferralFields.PATIENT_FIRSTNAME.getKey()), (String) params.get(EReferralFields.PATIENT_LASTNAME.getKey()));
            ksession.fireAllRules();


            // TODO This should be disposed but this fails within the transaction boundary.
//             ksession.dispose(); //dispose after use.
        }
        catch (Exception e)
        {
            throw new RuntimeException("Exception occurred.", e);
        }
    }



where the getSession method is


public StatefulKnowledgeSession getSession(int sessionId)
    {
        initialize();


        StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, kconfig, kenvironment);
        registerWorkItemHandlers(ksession);


        return ksession;
    }



Not sure how to proceed with this. Seems I need to get the container to dispose of the session after the transaction but that isn't possible with an MDB as far as I know.

thanks.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/748137#748137]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Amin Mohammed-Coleman
2012-07-18 08:04:42 UTC
Permalink
Amin Mohammed-Coleman [https://community.jboss.org/people/amin1977] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/748654#748654

--------------------------------------------------------------
You could register a transaction synchronisation to dispose of the session.  If you are using Spring you can use one of it's Transaction Synchronisation utility class to register the sync.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/748654#748654]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Brian Wallis
2012-07-24 00:09:12 UTC
Permalink
Brian Wallis [https://community.jboss.org/people/bwallis42] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/749736#749736

--------------------------------------------------------------
In our case the session is loaded inside the onMessage() method of a JEE Message Driven Bean. The JEE SessionSynchronization interface or the @AfterCompletion annotations are not available on MDBs. I'm not using spring.

It seems that there isn't a JEE6 way to run something after the transaction is committed for a MDB.

I think the only option with the MDB is to configure the bean for transactions NOT_SUPPORTED, start and commit my own transaction around the interaction with the workflow session and client mode message acknowledgement post the commit. I will also have to deal with the small chance of duplicate message delivery.

Somewhat more complex than I'd hoped for. Quite a major change required for an update from jbpm 5.1 to 5.3!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/749736#749736]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Amin Mohammed-Coleman
2012-07-24 07:18:24 UTC
Permalink
Amin Mohammed-Coleman [https://community.jboss.org/people/amin-mc] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/749781#749781

--------------------------------------------------------------
Haven't done any MDBs but don't you need to implement SessionSynchronisation interface?  Just wondering whether in the afterBegin(..) you create the session and the in the afterCompletion(..) dispose?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/749781#749781]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Brian Wallis
2012-07-24 07:23:48 UTC
Permalink
Brian Wallis [https://community.jboss.org/people/bwallis42] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/749786#749786

--------------------------------------------------------------
the session synchronisation and related annotations only apply to stateful session beans so out of luck with the MDBs.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/749786#749786]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Amin Mohammed-Coleman
2012-07-24 08:26:35 UTC
Permalink
Amin Mohammed-Coleman [https://community.jboss.org/people/amin-mc] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/749793#749793

--------------------------------------------------------------
darn it! i'm not sure why the behaviour of the dispose(..) changed from 5.2 to 5.3 (one of the reasons we held off from upgrading). 
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/749793#749793]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
sreeramk82
2012-10-29 11:23:04 UTC
Permalink
sreeramk82 [https://community.jboss.org/people/sreeramk82] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/772767#772767

--------------------------------------------------------------
Hi,

I am also facing the same issue. DId anyone get any workaround or identify the root cause

java.lang.IllegalStateException: Illegal method call. This session was previously disposed.
           org.drools.reteoo.DisposedReteooWorkingMemory.getWorkItemManager(DisposedReteooWorkingMemory.java:386)
           org.drools.impl.StatefulKnowledgeSessionImpl.getWorkItemManager(StatefulKnowledgeSessionImpl.java:311)
          org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:69)
          org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:32)

--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/772767#772767]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Gareth Edwards
2013-02-01 11:01:41 UTC
Permalink
Gareth Edwards [https://community.jboss.org/people/garethed] created the discussion

"Re: jbpm 5.3 - kSession.dispose() - Error: Session was previously disposed"

To view the discussion, visit: https://community.jboss.org/message/795593#795593

--------------------------------------------------------------
How can I tell if the transaction has completed?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/795593#795593]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...