5

We are trying to use Activiti in a new project. I've created a setup which uses Hibernate through JPA for persisting entities involved in the process and JPA is interconnected with Activiti so we can use these entities as JPA variables. See: JPA chapter of Activiti's documentation

I've found out that Activiti doesn't allow me to create queries on processes which involves JPA variables where i like to filter on the JPA entity fields. For example if i have processes with a variable referencing Book entities i can't create a query for processes which have a book with a specific title.

What's the best method to overcome this? I though about querying the entities seperately with Hibernate then do a second query on Activiti to get the processes involved however i'm affraid it will be slow. Also if i'm doing it the other way around (querying the processes first then do a second query with Hibernate on the entities) Activiti does an unnecessarry fill of the JPA variables and i couldn't find out how to get only the entity ID which saved into the Activiti variables table of my database.

NagyI
  • 5,907
  • 8
  • 55
  • 83
  • I'm trying to get around this by embedding the Activiti processInstanceId into the entity i'm using as a JPA variable. This way i have to only fetch processes which are interesting and i can get the process IDs without doing a fetch from JPA. Then i do a second query against JPA where the document ids are in the set what i described above. I'll see how it works. – NagyI Nov 14 '12 at 18:50

2 Answers2

0

what about using your entity's ID as businessKey of your process?

You could then do a query on your entities (Books with specific titles) and then use that to retrieve you processes in Activiti

rptmat57
  • 3,643
  • 1
  • 27
  • 38
  • I'm currently experimenting with the reverse of this. I've put the processInstanceId which the entity is involved in into the entity itself. – NagyI Nov 16 '12 at 20:40
  • I like the other way around because it doesn't require to change you entities and let your domain be independent of Activiti. in case you ever decide to use another workflow engine – rptmat57 Nov 16 '12 at 21:38
  • This doesn't work because you can't query for processes instances with a list of business keys. You can only query for a specific key. I think that's very inefficient to iterate through a JPA result list and query Activiti for each of them. – NagyI Nov 19 '12 at 10:16
0

I've implemented my solution descirbed in the questions comments. I don't yet have a big dataset to test performance but it seems acceptable.

NagyI
  • 5,907
  • 8
  • 55
  • 83