I'm having trouble reproducing your problem. Can you provide a code snippet which shows what you are trying to do?
The only reason I can imagine right now for the null process instance is that you had originally created the token with the default constructor, which does not set any field.
OK, I have found the problem and my mistake:
1.) I start a new process with a transition
2.) In this first transition a decision occurs
3.) The decision want to get a variable from the process, but doe not use the executionContext but a own class, which retrieves the token from the database (but the new process instance is not comitted yet).
That causes the problem!
No we work with the executionContext in the Decision and everything works fine!
Thanks for your effort!
OK, we still have a problem:
With session.getGraphSession().loadToken(tokenId) the processInstance in the token is always null! This is the root token of a process instance.
Even with session.getGraphSession().loadProcessInstance(tokenId).getRootToken()
the processInstance in this token is null!
Our process is started with:
ProcessInstance pi = session.getGraphSession().findLatestProcessDefinition(processName).createProcessInstance();
Any hints to that?
We also have to close the jBpmSession after every commit to work properly...
Strange, but I don't know hibernate so good (we use JDO ;-)), I think it makes sense in some way...
I see a connection between your problems and Daniel's problem with stale data in variable instances.
So, the only way things work properly for you is using the session for a single transaction? If you start a new transaction and load a token, its process instace is null?