Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 895814

Summary: Avoid updating ProcessInstanceInfo in JPAProcessInstanceManager.getProcessInstance()
Product: [JBoss] JBoss Enterprise BRMS Platform 5 Reporter: Toshiya Kobayashi <tkobayas>
Component: jBPM 5Assignee: Kris Verlaenen <kverlaen>
Status: CLOSED UPSTREAM QA Contact: Marek Baluch <mbaluch>
Severity: high Docs Contact:
Priority: unspecified    
Version: BRMS 5.3.1   
Target Milestone: ---   
Target Release: One Off Releases   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2025-02-10 03:27:17 UTC Type: Feature Request
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 873846    
Attachments:
Description Flags
jBPMEx55_getProcessInstance_SOSE_BRMS531.zip none

Description Toshiya Kobayashi 2013-01-16 04:02:59 UTC
Description of problem:

Platform BZ for https://issues.jboss.org/browse/JBPM-3902

How reproducible:

Concurrent accesses with ksession.getProcessInstance() for the same process instance.

Steps to Reproduce:
1. run ProcessMainJPA in attached jBPMEx55_getProcessInstance_SOSE_BRMS531.zip
  
Actual results:

Throws org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.jbpm.persistence.processinstance.ProcessInstanceInfo#338] intermittently


Expected results:

No exception

Comment 1 Toshiya Kobayashi 2013-01-16 04:13:33 UTC
Created attachment 679320 [details]
jBPMEx55_getProcessInstance_SOSE_BRMS531.zip

Comment 2 JBoss JIRA Server 2013-01-16 04:22:27 UTC
Toshiya Kobayashi <tkobayas> made a comment on jira JBPM-3902

Attaching a reproducer. Please run ProcessMainJPA.

Comment 3 JBoss JIRA Server 2013-01-28 08:22:32 UTC
Toshiya Kobayashi <tkobayas> made a comment on jira JBPM-3902

Adding a method like getProcessInstanceReadOnly() which doesn't update lastReadDate may be easier to implement but it would affect interfaces instead.

Comment 4 JBoss JIRA Server 2013-02-01 16:11:50 UTC
Andrey Moiseev <andrey.moiseev> made a comment on jira JBPM-3902

Now as a workaround we are using code like this

StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(...);
ProcessInstanceInfo pii = emf.createEntityManager().find(ProcessInstanceInfo.class, id);
ProcessInstance pi = pii.getProcessInstance(new StatefulKnowledgeSessionImpl((ReteooWorkingMemory) ((NamedEntryPoint) ksession
									.getWorkingMemoryEntryPoint("DEFAULT")).getInternalWorkingMemory()), ksession
									.getEnvironment());

Comment 5 JBoss JIRA Server 2013-02-17 00:56:31 UTC
Kris Verlaenen <kris.verlaenen> updated the status of jira JBPM-3902 to Resolved

Comment 6 Kris Verlaenen 2013-02-17 00:57:47 UTC
added method getProcessInstance(id, boolean readOnly)

Comment 7 Julian Coleman 2013-03-20 12:42:05 UTC
Included in roll-up #1: BZ-873846

Comment 8 Jiri Svitak 2013-04-02 17:41:15 UTC
Verified in roll-up patch BZ-873846 (5.3.1.BRMS-P02) using Toshiya's reproducer. Thanks!

Comment 9 JBoss JIRA Server 2013-08-13 21:53:39 UTC
Chris Wash <chris.wash> made a comment on jira JBPM-3902

Is there a patch to backport this fix to 5.4.0 Community?

Comment 10 JBoss JIRA Server 2013-10-30 21:38:43 UTC
Anselmo Abadía <anselmo.abadia> made a comment on jira JBPM-3902

My workaround:

1) Modify ProcessInstanceInfo persistence mapping. Make the lastReadDate's field transient.

<!--    <basic name="lastReadDate" access="FIELD" > -->
<!--      <temporal>TIMESTAMP</temporal> -->
<!-- </basic> -->

 <transient name="lastReadDate"/>

2) Dirty the current process instance at the end of each waitState. E.g completeHumanTask or signalEvent

E.g.
kSession.execute(new DirtyProcessInstanceInfo(kSession,
					processInstanceId));
kSession.signalEvent(type, event, processInstanceId);


public class DirtyProcessInstanceInfo implements GenericCommand<Object> {

	private final StatefulKnowledgeSession kSession;

	private final Long id;

	private static final long serialVersionUID = 1L;

	public DirtProcessInstanceInfo(StatefulKnowledgeSession kSession, long id) {
		this.kSession = kSession;
		this.id = id;
	}

	public Object execute(Context context) {
		EntityManager manager = (EntityManager) kSession.getEnvironment().get(
				EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);

		ProcessInstanceInfo processInstanceInfo = manager.find(
				ProcessInstanceInfo.class, id);
		FieldUtils.setProtectedFieldValue("lastModificationDate",
				processInstanceInfo, new Date());
		return null;
	}
}

3) Pray

Bye.

Comment 11 JBoss JIRA Server 2013-10-31 16:04:04 UTC
Anselmo Abadía <anselmo.abadia> made a comment on jira JBPM-3902

My workaround:

1) Modify ProcessInstanceInfo persistence mapping. Make the lastReadDate's field transient.
{code}
<!--    <basic name="lastReadDate" access="FIELD" > -->
<!--      <temporal>TIMESTAMP</temporal> -->
<!-- </basic> -->

 <transient name="lastReadDate"/>
{code}
2) Dirty the current process instance at the end of each waitState. E.g completeHumanTask or signalEvent

E.g.
{code}
kSession.execute(new DirtyProcessInstanceInfo(kSession,
					processInstanceId));
kSession.signalEvent(type, event, processInstanceId);
{code}
{code}
public class DirtyProcessInstanceInfo implements GenericCommand<Object> {

	private final StatefulKnowledgeSession kSession;

	private final Long id;

	private static final long serialVersionUID = 1L;

	public DirtProcessInstanceInfo(StatefulKnowledgeSession kSession, long id) {
		this.kSession = kSession;
		this.id = id;
	}

	public Object execute(Context context) {
		EntityManager manager = (EntityManager) kSession.getEnvironment().get(
				EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);

		ProcessInstanceInfo processInstanceInfo = manager.find(
				ProcessInstanceInfo.class, id);
		FieldUtils.setProtectedFieldValue("lastModificationDate",
				processInstanceInfo, new Date());
		return null;
	}
}
{code}
3) Pray

Bye.

Comment 14 Red Hat Bugzilla 2025-02-10 03:27:17 UTC
This product has been discontinued or is no longer tracked in Red Hat Bugzilla.