We have a problem saving an JPA entity within the execute
method of a Camunda JavaDelegate
. The entity is not persisted to the database.
When calling the same code from a normal Spring @RestController
, it works fine.
Short excerpt from our code:
@Component
@Transactional // do we need this...?
public class CreateUser implements JavaDelegate {
@Autowired private UserRepository userRepository;
@Override public void execute(DelegateExecution camunda) {
User user = new User(...);
userRepository.save(user); // The user is _not_ saved in the database
}
}
We compared the detailled log files when calling from JavaDelegate
and from the Spring @RestController
. They were identical, except the following lines just directly after userRepository.save
which are missing when calling from JavaDelegate
:
2019-04-30 12:17:55.759 DEBUG 9092 --- [nio-8080-exec-1] o.h.e.t.internal.TransactionImpl : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2019-04-30 12:17:55.759 DEBUG 9092 --- [nio-8080-exec-1] o.h.e.t.internal.TransactionImpl : begin
2019-04-30 12:17:56.019 TRACE 9092 --- [nio-8080-exec-1] j.i.AbstractLogicalConnectionImplementor : Preparing to begin transaction via JDBC Connection.setAutoCommit(false)
2019-04-30 12:17:56.040 TRACE 9092 --- [nio-8080-exec-1] j.i.AbstractLogicalConnectionImplementor : Transaction begun via JDBC Connection.setAutoCommit(false)
2019-04-30 12:17:56.040 TRACE 9092 --- [nio-8080-exec-1] cResourceLocalTransactionCoordinatorImpl : ResourceLocalTransactionCoordinatorImpl#afterBeginCallback
It seems as if no transaction is opened when calling from JavaDelegate
.
Any idea?