cancel
Showing results for 
Search instead for 
Did you mean: 

History query returns incorrect result set

frauke
Champ in-the-making
Champ in-the-making
Hello everybody,

the query

List<HistoricProcessInstance> his =processEngine.getHistoryService()
                    .createHistoricProcessInstanceQuery()
                    .processInstanceId(((ExecutionEntity) execution).getProcessInstanceId())
                    .list();
returns a list of all history entries, instead of a single line as expected.
And the single result query throws an exception

HistoricProcessInstance his =processEngine.getHistoryService()
                    .createHistoricProcessInstanceQuery()
                    .processInstanceId(((ExecutionEntity) execution).getProcessInstanceId())
                    .singleResult();
When I inspect the database table, there is only one record with the expected process instance id.

Frauke
9 REPLIES 9

tombaeyens
Champ in-the-making
Champ in-the-making

frederikherema1
Star Contributor
Star Contributor
Frauke,

I double-checked the HistoricProcessInctance tests an queries, couldn't find any issues there.

Which version of activiti are you running?
Can you provide a bit more context about where you are using the code pasted above?

regards

frauke
Champ in-the-making
Champ in-the-making
Hello Frederik,

I am using Activiti 5.0 beta2 and the place were I call the history query is inside an instance of BpmnActivityBehavior.

Thank you for checking.
Best regards Frauke

frederikherema1
Star Contributor
Star Contributor
Frauke,

Can you add your BpmnActivityBehaviour to a simple process and a testcase that shows the behaviour that you were talking about? I can't seem to reproduce it.

You can just attach it to the issue http://jira.codehaus.org/browse/ACT-248

frauke
Champ in-the-making
Champ in-the-making
Ok, I attached the test files to the jira issue.

frederikherema1
Star Contributor
Star Contributor
This test runs green in eclipse on 5.0.rc1-SNAPSHOT on trunk.

However, you shouldn't do engine API-calls from within a BpmnJavaDelegation (or Activitybehaviour/EventListener). This could mess up transactions/command contexts, and is probably why you get unexpected results.

frauke
Champ in-the-making
Champ in-the-making
Ok, I have the following problem:
the process modifies some object and I would like to store some process information with the object when saving it in the database.
So to say, which process modified it at which time, etc. So I thought reading the process history entry before storing the object would do.

Are there any other possibilitites to solve such a problem with Activiti?

jbarrez
Star Contributor
Star Contributor
Could you clarify that a bit with a code snippet?
What exactly do you want to store in the object ?

frauke
Champ in-the-making
Champ in-the-making
Ok, I think about something like this:
But I got the point about messing up the transactional context that frederik mentioned in his post.


public class CreateObjectTask extends BpmnActivityBehavior implements ActivityBehavior {
    @Override
    public void execute(final ActivityExecution execution) throws Exception {
        MyObject o = new MyObject();
        String pid = ((ExecutionEntity) execution).getProcessInstanceId();
        HistoricProcessInstance his = processEngine.getHistoryService()
            .createHistoricProcessInstanceQuery()
            .processInstanceId(pid)
            .singleResult();
        if (his != null) {
            o.setProcessInstance(his.getProcessInstanceId());
            o.setProcessHistoryId(his.getId());
            o.setProcessStartedOn(his.getStartTime());
        }
        o.save();
    }
}