JPA with case management

27 views
Skip to first unread message

Motamedi

unread,
Nov 20, 2018, 1:53:53 PM11/20/18
to jBPM Development
Hi Maciej,

I'm trying to setup JPA for a Case Management project using JBPM 7.13.0.Final. 
I have an entity extending VariableEntity which is used as a case file variable. The deployment is successful and JPA/Hibernate  creates the model table in database as well as MAPPEDVARIABLE table.
When I update the case through REST API, my model table gets populated but no record inserted into MAPPEDVARIABLE table.

Turns out org.drools.persistence.jpa.marshallerJPAPlaceholderResolverStrategy skips adding the records to MAPPEDVARIBALE.
Did some debugging, found out the following condition  in addMapping is always false because context is instance of MarshallerWriteContext not ProcessMarshallerWriteContext so it never get passed that point.

context instanceof ProcessMarshallerWriteContex

So my question is: is that an expected behavior?

I also tried to find a workaround by changing the code to something like following which fixed the issue (MAPPEDVARIBALE table gets populated as expected) but I wasn't if that's a right approach or the root cause is something else:

    protected void addMapping(Object entityId, String entityType, Object entity, ObjectOutputStream context, EntityManager em) {
 
if (!(entityId instanceof Number) || !(entity instanceof VariableEntity)) {
 
return;
 
}
 
 
Long processInstanceId = null;
 
Long taskId = null;
 
Long workItemId = null;
 java
.lang.Integer state = null;
 
 
if (context instanceof MarshallerWriteContext) {
 
KieSession ksession = (KieSession)((MarshallerWriteContext)context).wm;


 
Collection<ProcessInstance> instances = ksession.getProcessInstances();


 
if (instances.isEmpty()) {
 
return;
 
}
 
 
ProcessInstance instance = instances.iterator().next();
 processInstanceId
= instance.getId();
 state
= instance.getState();
 
} else if (context instanceof ProcessMarshallerWriteContext) {
           
ProcessMarshallerWriteContext processContext = (ProcessMarshallerWriteContext) context;
 processInstanceId
= processContext.getProcessInstanceId();
 state
= processContext.getState();
 taskId
= processContext.getTaskId();
 workItemId
= processContext.getWorkItemId();
 
} else {
 
return;
 
}
 
 
VariableEntity variableEntity = (VariableEntity) entity;
 
 
MappedVariable mappedVariable = new MappedVariable(((Number)entityId).longValue(), entityType, processInstanceId, taskId, workItemId);
 
if (state == ProcessInstance.STATE_ACTIVE) {
 variableEntity
.addMappedVariables(mappedVariable);
 
} else {
 
MappedVariable toBeRemoved = variableEntity.findMappedVariables(mappedVariable);
 
if (toBeRemoved != null) {
 toBeRemoved
= em.find(MappedVariable.class, toBeRemoved.getMappedVarId());
 em
.remove(toBeRemoved);


 variableEntity
.removeMappedVariables(toBeRemoved);
 
}
 
}
   
}

Thanks for your time.

Motamedi

unread,
Nov 20, 2018, 9:41:05 PM11/20/18
to jBPM Development
Attached the modified JPAPlaceholderResolverStrategy just in case.
JPAPlaceholderResolverStrategy.java

Maciej Swiderski

unread,
Nov 21, 2018, 1:51:53 AM11/21/18
to Motamedi, jBPM Development

On 21 Nov 2018, at 03:41, Motamedi <mota...@urdeveloper.com> wrote:

Attached the modified JPAPlaceholderResolverStrategy just in case.

On Tuesday, 20 November 2018 11:53:53 UTC-7, Motamedi wrote:
Hi Maciej,

I'm trying to setup JPA for a Case Management project using JBPM 7.13.0.Final. 
I have an entity extending VariableEntity which is used as a case file variable. The deployment is successful and JPA/Hibernate  creates the model table in database as well as MAPPEDVARIABLE table.
When I update the case through REST API, my model table gets populated but no record inserted into MAPPEDVARIABLE table.

Turns out org.drools.persistence.jpa.marshallerJPAPlaceholderResolverStrategy skips adding the records to MAPPEDVARIBALE.
Did some debugging, found out the following condition  in addMapping is always false because context is instance of MarshallerWriteContext not ProcessMarshallerWriteContext so it never get passed that point.

context instanceof ProcessMarshallerWriteContex

So my question is: is that an expected behavior?
Yes, this is expected as case file data is not really associated with particular process instance. It can be modified by many process instances like subprocess of your case makes changes to that variable and then complete, this would make your setup out of date as it would point to process instance that is no longer active.

Instead there is already populated table called CaseFileDataLog that allows to easily find case file variables and that keeps association between data and case id (and some other data). If you need to join your custom entity table with this table you can implement toString of your entity to return value you want to join by.


I also tried to find a workaround by changing the code to something like following which fixed the issue (MAPPEDVARIBALE table gets populated as expected) but I wasn't if that's a right approach or the root cause is something else:
As described above this might make your mapping table out of date if there are multiple process instance involved in a case or your simply reopen case instance. So I would discourage to use this approach.

Maciej
-- 
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-development/0d08e6ea-83c7-4fc7-8d9b-9f08bb3341f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<JPAPlaceholderResolverStrategy.java>

Motamedi

unread,
Nov 21, 2018, 10:43:38 AM11/21/18
to jBPM Development
Thanks for the information. I've check CaseFileDataLog but it seems only have records for case data provided when starting a case or when you update case data directly through REST API. So all the case data added by Human Tasks are missing from this table but exist in VaribaleInstanceLog as "caseFile_xxx". 
Maciej
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-development+unsub...@googlegroups.com.

Maciej Swiderski

unread,
Nov 21, 2018, 12:16:32 PM11/21/18
to Motamedi, jBPM Development
That’s a valid point, could you please open Jira and I wi look into it next week

Maciej 

Wiadomość napisana przez Motamedi <mota...@urdeveloper.com> w dniu 21.11.2018, o godz. 16:43:

To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.

To post to this group, send email to jbpm-dev...@googlegroups.com.

Motamedi

unread,
Nov 21, 2018, 1:32:54 PM11/21/18
to jBPM Development
Thanks for prompt response!
I'll create a JIRA and let you know the number.
To give more background (I hope that would help), that's what I understand:

CaseInstanceAuditEventListener is responsible for updating CaseDataLog table.
CaseDataLog manipulation happens afterCaseStarted, afterCaseReopen, afterCaseDataAdded and afterCaseDataRemoved.
- afterCaseDataAdded is only fired by AddDataCaseFileInstanceCommand.
When completion of task makes changes to case file (process variables), CaseFileInstanceMarshallingStrategy.marshall is called but not by any of case commands. The stack dump is attached just in case
StackDumpt.txt

Motamedi

unread,
Nov 21, 2018, 1:50:16 PM11/21/18
to jBPM Development
Reply all
Reply to author
Forward
0 new messages