AnsweredAssumed Answered

JPA integration not working 100% for transient variables???

Question asked by tbee on Sep 6, 2012
Latest reply on Sep 6, 2012 by tbee
I've setup JPA integration and initially it seems to work, but I find a deviation.

My entity classes all extend an AbstractBean class where the code for a.o. property change events is present. This class also has the possibility to block (ignore) these events (this is required when setting up default values, you do not want the entity to become marked "dirty"). Anyhow, in order to block these events there is a transient property in the abstract bean class:


@Transient transient final public AtomicInteger ignoreChangesGate = new AtomicInteger();

I've changed that property temporarly to public, so I can inspect it. Now, when a entity is put into the variables map at the starting of a workflow, this property naturally is not null:


      Map<String, Object> lProcessVariables = new HashMap<>();
      lProcessVariables.put("a", this);
      System.out.println("!!!1 iIgnoreChangesGate = " + this.ignoreChangesGate);
      ProcessInstance lProcessInstance = lProcessEngine.getRuntimeService().startProcessInstanceByKey("frozn", lProcessVariables);

A bit later in the process a task listener is called, which fetches this variable:


   @Override
   public void notify(org.activiti.engine.delegate.DelegateTask delegateTask)
   {
      Application lApplication = (Application)delegateTask.getVariable("a");
      System.out.println("!!!2 iIgnoreChangesGate = " + lApplication.ignoreChangesGate);
      …

When this workflow is run, the following output appears on the console:


!!!1 iIgnoreChangesGate = 0
!!!2 iIgnoreChangesGate = null

The transient property has not been initialized?!! This is very strange, since it is final and the constructor has finished.
So as a test I simply reloaded the entity from the EM.


   @Override
   public void notify(org.activiti.engine.delegate.DelegateTask delegateTask)
   {
      Application lApplication = (Application)delegateTask.getVariable("a");
      System.out.println("!!!2 iIgnoreChangesGate = " + lApplication.ignoreChangesGate);
      // reload
      lApplication = (Application)lEntityManager.find(Application.class, lApplication.getApplicationId());
      System.out.println("!!!3 iIgnoreChangesGate = " + lApplication.ignoreChangesGate);
      …

The output now is:


!!!1 iIgnoreChangesGate = 0
!!!2 iIgnoreChangesGate = null
!!!3 iIgnoreChangesGate = 0

So something is not going right when restoring the entity.

Outcomes