Discussion:
[jboss-user] [jBPM] - WorkflowProcessInstanceUpgrader throwing
Marcelo Zabalet
2013-01-09 17:45:44 UTC
Permalink
Marcelo Zabalet [https://community.jboss.org/people/zabalet] created the discussion

"WorkflowProcessInstanceUpgrader throwing ClassCastException: ...CommandBasedStatefulKnowledgeSession cannot be cast to ...InternalKnowledgeRuntime"

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

--------------------------------------------------------------
Hi people!

I'm having this issue trying to upgrade process intances using WorkflowProcessInstanceUpgrader as described at http://docs.jboss.org/jbpm/v5.4/userguide/ch.core-basics.html#d0e2318 http://docs.jboss.org/jbpm/v5.4/userguide/ch.core-basics.html#d0e2318

This is the line creating the knowledgeSession:

ksession = JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, null, env);


and this is the line trying to upgrade:

WorkflowProcessInstanceUpgrader.upgradeProcessInstance(knowledgeSession, processInstance.getId(), newProcessDefinitionId, mapping);


Inside https://github.com/droolsjbpm/jbpm/blob/5.4.0.Final/jbpm-flow/src/main/java/org/jbpm/workflow/instance/WorkflowProcessInstanceUpgrader.java WorkflowProcessInstanceUpgrader there is the casting causing the problem

processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime);


The point is that CommandBasedStatefulKnowledgeSession does not implements InternalKnowledgeRuntime like his counterparts implementing StatefulKnowledgeSession.

   _StatefulKnowledgeSession
    |__CommandBasedStatefulKnowledgeSession (NOT implements InternalKnowledgeRuntime)
    |__StatefulKnowledgeSessionImpl (implements InternalKnowledgeRuntime)
    |__StatefulProcessSession (implements InternalKnowledgeRuntime)


Then:

- Should CommandBasedStatefulKnowledgeSession implement InternalKnowledgeRuntime like his counterparts?

- Should I use a different implementation of StatefulKnowledgeSession?

- There is a bigger issue around this inherent to the command based nature?

(This same issue was somehow asked https://community.jboss.org/message/634907#634907 here (https://community.jboss.org/message/634907#634907) but there was no feedback)

TIA.

Marcelo.
--------------------------------------------------------------

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

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

"Re: WorkflowProcessInstanceUpgrader throwing ClassCastException: ...CommandBasedStatefulKnowledgeSession cannot be cast to ...InternalKnowledgeRuntime"

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

--------------------------------------------------------------
Ok, have sense... CommandBasedStatefulKnowledgeSession is more like a wrapper. So, this works, although IÂŽm not sure about so much casting...

CommandBasedStatefulKnowledgeSession commandBasedKSession = (CommandBasedStatefulKnowledgeSession) knowledgeSession;
CommandService commandService = commandBasedKSession.getCommandService();
SingleSessionCommandService singleSessionCommandService = (SingleSessionCommandService) commandService;
StatefulKnowledgeSession statefulKnowledgeSession = singleSessionCommandService.getStatefulKnowledgeSession();
WorkflowProcessInstanceUpgrader.upgradeProcessInstance(statefulKnowledgeSession , processInstance.getId(), targetProcessDefinitionId, mapping);
--------------------------------------------------------------

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

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

"Re: WorkflowProcessInstanceUpgrader throwing ClassCastException: ...CommandBasedStatefulKnowledgeSession cannot be cast to ...InternalKnowledgeRuntime"

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

--------------------------------------------------------------
Marcelo, maybe you could try something like this instead of all this casts:

        StatefulKnowledgeSession ks = ksession.execute(new GenericCommand<StatefulKnowledgeSession>() {
public StatefulKnowledgeSession execute(Context context) {
return ((KnowledgeCommandContext) context).getStatefulKnowledgesession();

            }
        });
where ksession is CommandBasedStatefulKnowledgeSession and ks will be its undelying InternalKnowledgeRuntime.

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

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

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

"Re: WorkflowProcessInstanceUpgrader throwing ClassCastException: ...CommandBasedStatefulKnowledgeSession cannot be cast to ...InternalKnowledgeRuntime"

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

--------------------------------------------------------------
Ah! I see it now, this and the other post :) . Thanks a lot Maciej.
--------------------------------------------------------------

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

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