AnsweredAssumed Answered

Issue found in activiti-engine with JPA entities and hibernate

Question asked by jose.gomez on Aug 19, 2016
We've found a scenario that causes JPA entities not to be correctly persisted when using the last version of activiti 5 (5.21.0) and Hibernate 3.

The problem appears when the object to be persisted is a proxy; in this case the JPAEntityScanner finds that the member variable uses @Id (1) so when it extracts its value (2) in JPAEntityMappings, it extracts the value of the member variable, and the problem is that the proxy's member variable is not initialised because the expected way of accessing the value is via the getter, so it is resolved that the primary key is null/0

This issue would happen with any version of Hibernate as the problem is because of the proxy.

The current workaround that we apply is just unproxying the object so Activiti can extract correctly the variable's value.

The interesting thing with this scenario is that it's difficult to know when it's going to fail as different execution flows could cause that the element to persist is a real object or a proxy object, so it may happen "randomly". One symptom is that there are jpa-entities with value 0:

select * from ACT_RU_VARIABLE where TYPE_ = 'jpa-entity' and TEXT2_ = 0;

I've uploaded the test to google-drive