Hibernate not flushing entity update on transaction commit - spring-boot

This is the transactional service defining the method I use to create a UserCommit and explicitly persisting it (this part works), and in the meantime updating the lastCommit field of the already existent parent entity User. This update doesn't get flushed.
#Transactional
#Service
public class UserCommitService {
#Autowired
private UserService userService;
#Autowired
private UserCommitRepository ucRepo;
public UserCommit createFrom(User user, Integer prodId, String ucType, String stage) {
UserCommit uc = new UserCommit();
uc.setUser(userService.findUserById(user.getId()));
uc.getUser().addUserCommit(uc);
uc.setTime(LocalDateTime.now());
uc.getUser().setLastCommit(uc.getTime());
ucRepo.save(uc);
return uc;
}
}
Here you can read the tracing log:
User gets correctly selected from DB
An inner transaction gets created for ucRepo.save (It's a CRUDRepo method, then I think it's normal) and userCommit gets correctly inserted into DB
EDIT
Why CrudRepository.save creates a new transaction instead of joining the existing one?
Outer transaction gets resumed, but even if the entity show the updated field, it seems this gets ignored by dirty checking, because no insert is logged on commit.
2020-05-31 12:52:36.405 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#296e6024] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#1826475] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:52:36.406 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(461939992<open>)] for JPA transaction
2020-05-31 12:52:36.406 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [petmenu.services.users.UserCommitService.createFrom]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-05-31 12:52:36.407 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#5ac66b8d]
2020-05-31 12:52:36.407 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.jdbc.datasource.ConnectionHolder#4905e3e7] for key [HikariDataSource (HikariPool-1)] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:52:36.407 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Initializing transaction synchronization
2020-05-31 12:52:36.407 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Getting transaction for [petmenu.services.users.UserCommitService.createFrom]
2020-05-31 12:53:24.212 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#296e6024] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#1826475] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:53:24.217 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(461939992<open>)] for JPA transaction
2020-05-31 12:53:24.221 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder#4905e3e7] for key [HikariDataSource (HikariPool-1)] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:53:24.228 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Participating in existing transaction
2020-05-31 12:53:24.232 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Getting transaction for [petmenu.services.users.UserService.findUserById]
2020-05-31 12:53:24.256 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : No need to create transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findUserById]: This method is not transactional.
2020-05-31 12:53:24.265 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.EntityManagerFactoryUtils : Opening JPA EntityManager
2020-05-31 12:53:24.271 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:53:24.279 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:53:24.288 DEBUG 7194 --- [.10-8080-exec-6] org.hibernate.SQL : select user0_.id as id1_0_, user0_.kc_id as kc_id2_0_, user0_.last_commit as last_com3_0_, user0_.name as name4_0_ from user user0_ where user0_.id=?
2020-05-31 12:53:24.298 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [6]
2020-05-31 12:53:24.309 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicExtractor : extracted value ([id1_0_] : [INTEGER]) - [6]
2020-05-31 12:53:24.317 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicExtractor : extracted value ([kc_id2_0_] : [VARCHAR]) - [80a3b4b1-00d1-4062-a7e5-1927b938c203]
2020-05-31 12:53:24.325 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicExtractor : extracted value ([last_com3_0_] : [TIMESTAMP]) - [null]
2020-05-31 12:53:24.332 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicExtractor : extracted value ([name4_0_] : [VARCHAR]) - [user1]
2020-05-31 12:53:24.342 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Completing transaction for [petmenu.services.users.UserService.findUserById]
2020-05-31 12:55:07.918 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$DefaultCrudMethodMetadata#326a9afb] for key [public abstract java.lang.Object org.springframework.data.repository.CrudRepository.save(java.lang.Object)] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:07.957 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:07.961 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1373582834<open>)] for JPA transaction
2020-05-31 12:55:07.966 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:07.970 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Clearing transaction synchronization
2020-05-31 12:55:07.975 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-05-31 12:55:07.980 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(756005269<open>)] for JPA transaction
2020-05-31 12:55:07.987 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#6860e795]
2020-05-31 12:55:07.992 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.jdbc.datasource.ConnectionHolder#6374741f] for key [HikariDataSource (HikariPool-2)] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:07.998 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.orm.jpa.EntityManagerHolder#4b2cad26] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:08.002 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Initializing transaction synchronization
2020-05-31 12:55:08.006 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
2020-05-31 12:55:08.226 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#4b2cad26] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] bound to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:08.392 DEBUG 7194 --- [.10-8080-exec-6] org.hibernate.SQL : select nextval(hibernate_sequence)
2020-05-31 12:55:08.783 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]
2020-05-31 12:55:08.787 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCommit synchronization
2020-05-31 12:55:08.791 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCompletion synchronization
2020-05-31 12:55:08.796 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-05-31 12:55:08.800 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(756005269<open>)]
2020-05-31 12:55:08.824 DEBUG 7194 --- [.10-8080-exec-6] org.hibernate.SQL : insert into user_commit (uctype, prod_id, stage, time, user, id) values (?, ?, ?, ?, ?, ?)
2020-05-31 12:55:08.832 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [1]
2020-05-31 12:55:08.838 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [INTEGER] - [3]
2020-05-31 12:55:08.845 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [INTEGER] - [0]
2020-05-31 12:55:08.884 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [TIMESTAMP] - [2020-05-31T12:54:58.518530]
2020-05-31 12:55:08.922 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [INTEGER] - [6]
2020-05-31 12:55:08.929 TRACE 7194 --- [.10-8080-exec-6] o.h.type.descriptor.sql.BasicBinder : binding parameter [6] as [INTEGER] - [3003]
2020-05-31 12:55:09.043 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering afterCommit synchronization
2020-05-31 12:55:09.048 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Clearing transaction synchronization
2020-05-31 12:55:09.052 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering afterCompletion synchronization
2020-05-31 12:55:09.056 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.orm.jpa.EntityManagerHolder#4b2cad26] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:09.062 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.jdbc.datasource.ConnectionHolder#6374741f] for key [HikariDataSource (HikariPool-2)] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:09.066 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(756005269<open>)] after transaction
2020-05-31 12:55:09.070 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Resuming suspended transaction after completion of inner transaction
2020-05-31 12:55:09.075 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Initializing transaction synchronization
2020-05-31 12:55:09.080 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] to thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:55:09.085 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$DefaultCrudMethodMetadata#326a9afb] for key [public abstract java.lang.Object org.springframework.data.repository.CrudRepository.save(java.lang.Object)] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:58:18.989 TRACE 7194 --- [.10-8080-exec-6] o.s.t.i.TransactionInterceptor : Completing transaction for [petmenu.services.users.UserCommitService.createFrom]
2020-05-31 12:58:18.997 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCommit synchronization
2020-05-31 12:58:19.001 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCompletion synchronization
2020-05-31 12:58:19.006 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.orm.jpa.EntityManagerHolder#75c27c80] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6c8672b9] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:58:19.071 INFO 7194 --- [.10-8080-exec-6] o.h.c.i.AbstractPersistentCollection : HHH000496: Detaching an uninitialized collection with queued operations from a session: [petmenu.entities.users.User.userCommitList#6]
2020-05-31 12:58:19.075 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-05-31 12:58:19.081 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(461939992<open>)]
2020-05-31 12:58:19.095 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering afterCommit synchronization
2020-05-31 12:58:19.099 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Clearing transaction synchronization
2020-05-31 12:58:19.104 TRACE 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Triggering afterCompletion synchronization
2020-05-31 12:58:19.109 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.jdbc.datasource.ConnectionHolder#4905e3e7] for key [HikariDataSource (HikariPool-1)] from thread [http-nio-192.168.1.10-8080-exec-6]
2020-05-31 12:58:19.113 DEBUG 7194 --- [.10-8080-exec-6] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2020-05-31 12:59:07.063 TRACE 7194 --- [.10-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.orm.jpa.EntityManagerHolder#296e6024] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#1826475] from thread [http-nio-192.168.1.10-8080-exec-6]
EDIT2
I tried to remove the CrudRepository.save call, because it behaves strangely, creating a new transaction on its own, and seems responsible for previous one closing. The log becomes a little more logic, but still User.lastCommit new value doesn't get flushed.
2020-06-01 11:39:10.518 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#5f0cca8f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#27bbe773] bound to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:10.518 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(2096513672<open>)] for JPA transaction
2020-06-01 11:39:10.518 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [petmenu.services.users.UserCommitService.createFrom]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-06-01 11:39:10.518 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#62cbdd03]
2020-06-01 11:39:10.519 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.jdbc.datasource.ConnectionHolder#4b988820] for key [HikariDataSource (HikariPool-1)] to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:10.519 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Initializing transaction synchronization
2020-06-01 11:39:10.519 TRACE 26420 --- [.10-8080-exec-2] o.s.t.i.TransactionInterceptor : Getting transaction for [petmenu.services.users.UserCommitService.createFrom]
2020-06-01 11:39:16.678 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#5f0cca8f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#27bbe773] bound to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:16.683 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(2096513672<open>)] for JPA transaction
2020-06-01 11:39:16.688 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder#4b988820] for key [HikariDataSource (HikariPool-1)] bound to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:16.693 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Participating in existing transaction
2020-06-01 11:39:16.697 TRACE 26420 --- [.10-8080-exec-2] o.s.t.i.TransactionInterceptor : Getting transaction for [petmenu.services.users.UserService.findUserById]
2020-06-01 11:39:16.720 TRACE 26420 --- [.10-8080-exec-2] o.s.t.i.TransactionInterceptor : No need to create transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findUserById]: This method is not transactional.
2020-06-01 11:39:16.727 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.EntityManagerFactoryUtils : Opening JPA EntityManager
2020-06-01 11:39:16.733 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Bound value [org.springframework.orm.jpa.EntityManagerHolder#ca14c2f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#161c9468] to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:16.738 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#ca14c2f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#161c9468] bound to thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:16.747 DEBUG 26420 --- [.10-8080-exec-2] org.hibernate.SQL : select user0_.id as id1_0_, user0_.kc_id as kc_id2_0_, user0_.last_commit as last_com3_0_, user0_.name as name4_0_ from user user0_ where user0_.id=?
2020-06-01 11:39:16.754 TRACE 26420 --- [.10-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [6]
2020-06-01 11:39:16.763 TRACE 26420 --- [.10-8080-exec-2] o.h.type.descriptor.sql.BasicExtractor : extracted value ([id1_0_] : [INTEGER]) - [6]
2020-06-01 11:39:16.772 TRACE 26420 --- [.10-8080-exec-2] o.h.type.descriptor.sql.BasicExtractor : extracted value ([kc_id2_0_] : [VARCHAR]) - [80a3b4b1-00d1-4062-a7e5-1927b938c203]
2020-06-01 11:39:16.779 TRACE 26420 --- [.10-8080-exec-2] o.h.type.descriptor.sql.BasicExtractor : extracted value ([last_com3_0_] : [TIMESTAMP]) - [null]
2020-06-01 11:39:16.787 TRACE 26420 --- [.10-8080-exec-2] o.h.type.descriptor.sql.BasicExtractor : extracted value ([name4_0_] : [VARCHAR]) - [user1]
2020-06-01 11:39:16.795 TRACE 26420 --- [.10-8080-exec-2] o.s.t.i.TransactionInterceptor : Completing transaction for [petmenu.services.users.UserService.findUserById]
2020-06-01 11:39:48.779 TRACE 26420 --- [.10-8080-exec-2] o.s.t.i.TransactionInterceptor : Completing transaction for [petmenu.services.users.UserCommitService.createFrom]
2020-06-01 11:39:48.780 TRACE 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCommit synchronization
2020-06-01 11:39:48.780 TRACE 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Triggering beforeCompletion synchronization
2020-06-01 11:39:48.780 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.orm.jpa.EntityManagerHolder#ca14c2f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#161c9468] from thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:48.782 INFO 26420 --- [.10-8080-exec-2] o.h.c.i.AbstractPersistentCollection : HHH000496: Detaching an uninitialized collection with queued operations from a session: [petmenu.entities.users.User.userCommitList#6]
2020-06-01 11:39:48.782 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-06-01 11:39:48.782 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(2096513672<open>)]
2020-06-01 11:39:48.787 TRACE 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Triggering afterCommit synchronization
2020-06-01 11:39:48.787 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Clearing transaction synchronization
2020-06-01 11:39:48.787 TRACE 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Triggering afterCompletion synchronization
2020-06-01 11:39:48.787 TRACE 26420 --- [.10-8080-exec-2] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.jdbc.datasource.ConnectionHolder#4b988820] for key [HikariDataSource (HikariPool-1)] from thread [http-nio-192.168.1.10-8080-exec-2]
2020-06-01 11:39:48.787 DEBUG 26420 --- [.10-8080-exec-2] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction

I spent just 4 days to realize the what the problem was. Awesome...(To be honest, I took advantage of all the stuff I had to read about JPA and Hibernate to get rid completely of OSIV).
When I defined my two datasources (Products and Users) configs, I annotated all the classes inside ProductsDataSourceConfiguration as #Primary, making them the default values when called without explicitly setting a name.
The problem was with PlatformTransactionManager in it, that was called as transaction manager for both my datasources, while actually being crafted just for Products one.
To solve the issue I had to specify the secondary transaction manager name on #Transactional annotation used on methods referring to secondary (Users) datasource:
#Transactional("usersTransactionManager")
#Service
public class UserCommitService {
...

Related

Spring Data Rest doesn't rollback after Access Denied Exception

I have an application built with Spring Data Rest, when saving an entity using an unauthorized account through preAuthorize, the system throws the Access Denied exception, however the registration is performed. Analyzing the log below it is possible to see a jpaTransaction performing a flush and updating the entity before the exception. Can anyone tell me how to avoid saving in this case or how I can perform a rollback?
... com.mysql.cj.jdbc.result.ResultSetImpl#2393ebf8]
2022-10-19 13:20:11.320 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Closing prepared statement [HikariProxyPreparedStatement#91893682 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: select chain0_.category_id as category1_3_0_, c... where chain0_.category_id=13122]
2022-10-19 13:20:11.321 TRACE 705721 --- [nio-8080-exec-6] o.h.e.j.i.JdbcCoordinatorImpl : Starting after statement execution processing [ON_CLOSE]
2022-10-19 13:20:11.321 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.StatefulPersistenceContext : Initializing non-lazy collections
2022-10-19 13:20:11.321 DEBUG 705721 --- [nio-8080-exec-6] stractLoadPlanBasedCollectionInitializer : Done loading collection
2022-10-19 13:20:11.321 TRACE 705721 --- [nio-8080-exec-6] DefaultInitializeCollectionEventListener : Collection initialized
2022-10-19 13:20:13.373 DEBUG 705721 --- [SchedulerThread] o.q.c.QuartzSchedulerThread : batch acquisition of 0 triggers
2022-10-19 13:20:13.423 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.name is dirty
2022-10-19 13:20:13.423 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.updateDate is dirty
2022-10-19 13:20:13.423 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.DefaultFlushEntityEventListener : Found dirty properties [[com.springboot.api.entities.Category#13122]] : [name, updateDate]
2022-10-19 13:20:13.423 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Versioning : Incrementing: 76 to 77
2022-10-19 13:20:13.424 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.Collections : Collection found: [com.springboot.api.entities.Category.chain#13122], was: [com.springboot.api.entities.Category.chain#13122] (initialized)
2022-10-19 13:20:13.424 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Processing unreferenced collections
2022-10-19 13:20:13.425 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Scheduling collection removes/(re)creates/updates
2022-10-19 13:20:13.425 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects
2022-10-19 13:20:13.425 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
2022-10-19 13:20:13.425 DEBUG 705721 --- [nio-8080-exec-6] o.h.i.u.EntityPrinter : Listing entities:
2022-10-19 13:20:13.425 DEBUG 705721 --- [nio-8080-exec-6] o.h.i.u.EntityPrinter : com.springboot.api.entities.Category{chain=[], updateDate=2022-10-19T13:20:08.095108, typeCategoryResultReports=NOT_APPLIED, businessAccount=com.springboot.api.entities.BusinessAccount#13119, description=Conta somatória de vendas dos produtos e serviços., typeResultReports=NOT_APPLIED_TO_DRE, typeCategory=INCOME, version=77, ordder=1, deleted=false, name=RECEITAS DE VENDAS 789, parentCategory=null, id=13122, createDate=2022-07-25T11:06:40, enumerated=1}
2022-10-19 13:20:13.426 DEBUG 705721 --- [nio-8080-exec-6] o.h.i.u.EntityPrinter : com.springboot.api.entities.BusinessAccount{updateDate=2022-07-25T11:07:46, active=true, contactPerson=Erik, version=1, legalName=Erick e Tatiane Restaurante Ltda, deleted=false, blocked=false, phone=1138234204, name=ERIT Restaurante Ltda, tin=02669055000114, id=13119, businessAccountParent=null, email=timlerirde#vusra.com, createDate=2022-07-25T11:06:36}
2022-10-19 13:20:13.426 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.DefaultAutoFlushEventListener : Don't need to execute flush
2022-10-19 13:20:13.426 TRACE 705721 --- [nio-8080-exec-6] o.h.e.q.s.HQLQueryPlan : Find: select b from BusinessAccount b where b.deleted = false and b.id = :id
2022-10-19 13:20:13.426 TRACE 705721 --- [nio-8080-exec-6] o.h.e.s.QueryParameters : Named parameters: {id=13119}
2022-10-19 13:20:13.426 DEBUG 705721 --- [nio-8080-exec-6] o.h.SQL : select businessac0_.id as id1_1_, ... where businessac0_.deleted=0 and businessac0_.id=?
2022-10-19 13:20:13.427 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Registering statement [HikariProxyPreparedStatement#1827444228 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: select businessac0_.id as id1_1_, businessac0_.active as active2_1_, ... businessac0_.id=** NOT SPECIFIED **]
2022-10-19 13:20:13.427 TRACE 705721 --- [nio-8080-exec-6] o.h.e.j.i.JdbcCoordinatorImpl : Registering last query statement [HikariProxyPreparedStatement#1827444228 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: select businessac0_.id as id1_1_, businessac0_.active as active2_1_, ... businessac0_.version as version13_1_ from business_account businessac0_ where businessac0_.deleted=0 and businessac0_.id=** NOT SPECIFIED **]
2022-10-19 13:20:13.428 TRACE 705721 --- [nio-8080-exec-6] o.h.t.d.s.BasicBinder : binding parameter [1] as [BIGINT] - [13119]
2022-10-19 13:20:13.428 TRACE 705721 --- [nio-8080-exec-6] o.h.l.Loader : Bound [2] parameters total
2022-10-19 13:20:13.583 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Registering result set [HikariProxyResultSet#212627179 wrapping com.mysql.cj.jdbc.result.ResultSetImpl#305c88ad]
2022-10-19 13:20:13.584 TRACE 705721 --- [nio-8080-exec-6] o.h.l.Loader : Processing result set
2022-10-19 13:20:13.584 DEBUG 705721 --- [nio-8080-exec-6] o.h.l.Loader : Result set row: 0
2022-10-19 13:20:13.584 TRACE 705721 --- [nio-8080-exec-6] o.h.t.d.s.BasicExtractor : extracted value ([id1_1_] : [BIGINT]) - [13119]
2022-10-19 13:20:13.585 DEBUG 705721 --- [nio-8080-exec-6] o.h.l.Loader : Result row: EntityKey[com.springboot.api.entities.BusinessAccount#13119]
2022-10-19 13:20:13.585 TRACE 705721 --- [nio-8080-exec-6] o.h.l.Loader : Done processing result set (1 rows)
2022-10-19 13:20:13.585 TRACE 705721 --- [nio-8080-exec-6] o.h.l.Loader : Total objects hydrated: 0
2022-10-19 13:20:13.586 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Releasing statement [HikariProxyPreparedStatement#1827444228 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: select businessac0_.id as id1_1_, businessac0_.active as active2_1_, businessac0_.blocked as blocked3_1_, businessac0_.business_account_parent_id as busines14_1_, businessac0_.contact_person as contact_4_1_, businessac0_.create_date as create_d5_1_, businessac0_.deleted as deleted6_1_, businessac0_.email as email7_1_, businessac0_.legal_name as legal_na8_1_, businessac0_.name as name9_1_, businessac0_.phone as phone10_1_, businessac0_.tin as tin11_1_, businessac0_.update_date as update_12_1_, businessac0_.version as version13_1_ from business_account businessac0_ where businessac0_.deleted=0 and businessac0_.id=13119]
2022-10-19 13:20:13.586 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Closing result set [HikariProxyResultSet#212627179 wrapping com.mysql.cj.jdbc.result.ResultSetImpl#305c88ad]
2022-10-19 13:20:13.586 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Closing prepared statement [HikariProxyPreparedStatement#1827444228 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: select businessac0_.id as id1_1_, businessac0_.active as active2_1_, businessac0_.blocked as blocked3_1_, businessac0_.business_account_parent_id as busines14_1_, businessac0_.contact_person as contact_4_1_, businessac0_.create_date as create_d5_1_, businessac0_.deleted as deleted6_1_, businessac0_.email as email7_1_, businessac0_.legal_name as legal_na8_1_, businessac0_.name as name9_1_, businessac0_.phone as phone10_1_, businessac0_.tin as tin11_1_, businessac0_.update_date as update_12_1_, businessac0_.version as version13_1_ from business_account businessac0_ where businessac0_.deleted=0 and businessac0_.id=13119]
2022-10-19 13:20:13.586 TRACE 705721 --- [nio-8080-exec-6] o.h.e.j.i.JdbcCoordinatorImpl : Starting after statement execution processing [ON_CLOSE]
2022-10-19 13:20:13.586 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.StatefulPersistenceContext : Initializing non-lazy collections
2022-10-19 13:20:13.589 TRACE 705721 --- [nio-8080-exec-6] o.s.t.i.TransactionInterceptor : Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById]
2022-10-19 13:20:13.589 TRACE 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Triggering beforeCommit synchronization
2022-10-19 13:20:13.589 TRACE 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Triggering beforeCompletion synchronization
2022-10-19 13:20:13.589 DEBUG 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Initiating transaction commit
2022-10-19 13:20:13.589 DEBUG 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(329218779PersistenceContext[entityKeys=[EntityKey[com.springboot.api.entities.Category#13122], EntityKey[com.springboot.api.entities.BusinessAccount#13119]], collectionKeys=[CollectionKey[com.springboot.api.entities.Category.chain#13122]]];ActionQueue[insertions=ExecutableList{size=0} updates=ExecutableList{size=0} deletions=ExecutableList{size=0} orphanRemovals=ExecutableList{size=0} collectionCreations=ExecutableList{size=0} collectionRemovals=ExecutableList{size=0} collectionUpdates=ExecutableList{size=0} collectionQueuedOps=ExecutableList{size=0} unresolvedInsertDependencies=null])]
2022-10-19 13:20:13.589 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.t.i.TransactionImpl : committing
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] cResourceLocalTransactionCoordinatorImpl : ResourceLocalTransactionCoordinatorImpl#beforeCompletionCallback
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] o.h.i.SessionImpl : SessionImpl#beforeTransactionCompletion()
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] o.h.i.SessionImpl : Automatically flushing session
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushing session
2022-10-19 13:20:13.590 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Processing flush-time cascades
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Cascade : Processing cascade ACTION_PERSIST_ON_FLUSH for: com.springboot.api.entities.Category
2022-10-19 13:20:13.590 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Cascade : Done processing cascade ACTION_PERSIST_ON_FLUSH for: com.springboot.api.entities.Category
2022-10-19 13:20:13.591 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Cascade : Processing cascade ACTION_PERSIST_ON_FLUSH for: com.springboot.api.entities.BusinessAccount
2022-10-19 13:20:13.592 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Cascade : Done processing cascade ACTION_PERSIST_ON_FLUSH for: com.springboot.api.entities.BusinessAccount
2022-10-19 13:20:13.592 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Dirty checking collections
2022-10-19 13:20:13.592 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushing entities and processing referenced collections
2022-10-19 13:20:13.593 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.name is dirty
2022-10-19 13:20:13.593 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.updateDate is dirty
2022-10-19 13:20:13.593 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.version is dirty
2022-10-19 13:20:13.593 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.DefaultFlushEntityEventListener : Found dirty properties [[com.springboot.api.entities.Category#13122]] : [name, updateDate, version]
2022-10-19 13:20:13.593 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.DefaultFlushEntityEventListener : Updating entity: [com.springboot.api.entities.Category#13122]
2022-10-19 13:20:16.443 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.name is dirty
2022-10-19 13:20:16.444 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.updateDate is dirty
2022-10-19 13:20:16.444 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : com.springboot.api.entities.Category.version is dirty
2022-10-19 13:20:16.444 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.DefaultFlushEntityEventListener : Found dirty properties [[com.springboot.api.entities.Category#13122]] : [name, updateDate, version]
2022-10-19 13:20:16.444 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.Versioning : Incrementing: 76 to 77
2022-10-19 13:20:16.445 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.Collections : Collection found: [com.springboot.api.entities.Category.chain#13122], was: [com.springboot.api.entities.Category.chain#13122] (initialized)
2022-10-19 13:20:16.445 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Processing unreferenced collections
2022-10-19 13:20:16.445 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Scheduling collection removes/(re)creates/updates
2022-10-19 13:20:16.445 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushed: 0 insertions, 1 updates, 0 deletions to 2 objects
2022-10-19 13:20:16.445 DEBUG 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
2022-10-19 13:20:16.445 DEBUG 705721 --- [nio-8080-exec-6] o.h.i.u.EntityPrinter : Listing entities:
2022-10-19 13:20:16.446 DEBUG 705721 --- [nio-8080-exec-6] o.h.i.u.EntityPrinter : com.springboot.api.entities.Category{chain=[], updateDate=2022-10-19T13:20:13.593846, typeCategoryResultReports=NOT_APPLIED, businessAccount=com.springboot.api.entities.BusinessAccount#13119, description=Conta somatória de vendas dos produtos e serviços., typeResultReports=NOT_APPLIED_TO_DRE, typeCategory=INCOME, version=77, ordder=1, deleted=false, name=RECEITAS DE VENDAS 789, ...
2022-10-19 13:20:16.446 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Executing flush
2022-10-19 13:20:16.447 TRACE 705721 --- [nio-8080-exec-6] o.h.v.i.e.c.SimpleConstraintTree : Validating value RECEITAS DE VENDAS 789 against constraint defined by ConstraintDescriptorImpl{annotation=j.v.c.NotEmpty, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={groups=[Ljava.lang.Class;#7375d1f6, message={name.required}, payload=[Ljava.lang.Class;#261e67fb}, constraintType=GENERIC, valueUnwrapping=DEFAULT}.
2022-10-19 13:20:16.454 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : Updating entity: [com.springboot.api.entities.Category#13122]
2022-10-19 13:20:16.454 TRACE 705721 --- [nio-8080-exec-6] o.h.p.e.AbstractEntityPersister : Existing version: 76 -> New version:77
2022-10-19 13:20:16.454 DEBUG 705721 --- [nio-8080-exec-6] o.h.SQL : update category set business_account_id=?, create_date=?, deleted=?, description=?, enumerated=?, name=?, ordder=?, parent_category_id=?, type_category=?, type_category_result_reports=?, type_result_reports=?, update_date=?, version=? where id=? and version=?
...
2022-10-19 13:20:16.461 TRACE 705721 --- [nio-8080-exec-6] o.h.t.d.s.BasicBinder : binding parameter [15] as [INTEGER] - [76]
2022-10-19 13:20:16.627 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Releasing statement [HikariProxyPreparedStatement#1680526329 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: update category set business_account_id=13119, create_date='2022-07-25 11:06:40.0', deleted=0, description='Conta somatória de vendas dos produtos e serviços.', enumerated='1', name='RECEITAS DE VENDAS 789', ordder='1', parent_category_id=null, type_category='INCOME', type_category_result_reports='NOT_APPLIED', type_result_reports='NOT_APPLIED_TO_DRE', update_date='2022-10-19 13:20:13.593846', version=77 where id=13122 and version=76]
2022-10-19 13:20:16.628 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Closing prepared statement [HikariProxyPreparedStatement#1680526329 wrapping com.mysql.cj.jdbc.ClientPreparedStatement: update category set business_account_id=13119, create_date='2022-07-25 11:06:40.0', deleted=0, description='Conta somatória de vendas dos produtos e serviços.', enumerated='1', name='RECEITAS DE VENDAS 789', ordder='1', parent_category_id=null, type_category='INCOME', type_category_result_reports='NOT_APPLIED', type_result_reports='NOT_APPLIED_TO_DRE', update_date='2022-10-19 13:20:13.593846', version=77 where id=13122 and version=76]
2022-10-19 13:20:16.628 TRACE 705721 --- [nio-8080-exec-6] o.h.e.j.i.JdbcCoordinatorImpl : Starting after statement execution processing [ON_CLOSE]
2022-10-19 13:20:16.629 TRACE 705721 --- [nio-8080-exec-6] o.h.e.j.i.JdbcCoordinatorImpl : Starting after statement execution processing [ON_CLOSE]
2022-10-19 13:20:16.629 TRACE 705721 --- [nio-8080-exec-6] o.h.e.i.AbstractFlushingEventListener : Post flush
2022-10-19 13:20:16.629 TRACE 705721 --- [nio-8080-exec-6] .t.i.SynchronizationRegistryStandardImpl : SynchronizationRegistryStandardImpl.notifySynchronizationsBeforeTransactionCompletion
2022-10-19 13:20:16.629 TRACE 705721 --- [nio-8080-exec-6] j.i.AbstractLogicalConnectionImplementor : Preparing to commit transaction via JDBC Connection.commit()
2022-10-19 13:20:16.786 TRACE 705721 --- [nio-8080-exec-6] j.i.AbstractLogicalConnectionImplementor : Transaction committed via JDBC Connection.commit()
2022-10-19 13:20:16.787 TRACE 705721 --- [nio-8080-exec-6] j.i.AbstractLogicalConnectionImplementor : re-enabling auto-commit on JDBC Connection after completion of JDBC-based transaction
2022-10-19 13:20:16.940 TRACE 705721 --- [nio-8080-exec-6] j.i.AbstractLogicalConnectionImplementor : LogicalConnection#afterTransaction
2022-10-19 13:20:16.940 TRACE 705721 --- [nio-8080-exec-6] o.h.r.j.i.ResourceRegistryStandardImpl : Releasing JDBC resources
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] cResourceLocalTransactionCoordinatorImpl : ResourceLocalTransactionCoordinatorImpl#afterCompletionCallback(true)
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] .t.i.SynchronizationRegistryStandardImpl : SynchronizationRegistryStandardImpl.notifySynchronizationsAfterTransactionCompletion(3)
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] o.h.i.SessionImpl : SessionImpl#afterTransactionCompletion(successful=true, delayed=false)
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Triggering afterCommit synchronization
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Clearing transaction synchronization
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Triggering afterCompletion synchronization
2022-10-19 13:20:16.941 TRACE 705721 --- [nio-8080-exec-6] .s.t.s.TransactionSynchronizationManager : Removed value [org.springframework.jdbc.datasource.ConnectionHolder#710d834f] for key [HikariDataSource (HikariPool-10)] from thread [http-nio-8080-exec-6]
2022-10-19 13:20:16.942 DEBUG 705721 --- [nio-8080-exec-6] o.s.o.j.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2022-10-19 13:20:16.952 TRACE 705721 --- [nio-8080-exec-6] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: [org.springframework.data.rest.webmvc.RootResourceInformation#6e5097f2, Resource { content: Category(id=13122, name=RECEITAS DE VENDAS 789, description=Conta somatória de vendas dos produtos e serviços., parentCategory=null, chain=null, typeCategory=INCOME, typeResultReports=NOT_APPLIED_TO_DRE, ordder=1, typeCategoryResultReports=NOT_APPLIED, businessAccount=BusinessAccount(id=13119, name=ERIT Restaurante Ltda, legalName=Erick e Tatiane Restaurante Ltda, tin=02669055000114, email=timlerirde#vusra.com, phone=1138234204, contactPerson=Erik, businessAccountParent=null, active=true, blocked=false, deleted=false, createDate=2022-07-25T11:06:36, updateDate=2022-07-25T11:07:46, version=1), deleted=false, createDate=2022-07-25T11:06:40, updateDate=2022-10-19T13:20:13.593846, version=76, enumerated=1, unselectable=false), links: [] }, 13122, org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler#299ef425, null, application/json;charset=UTF-8]
...
2022-10-19 13:20:16.959 TRACE 705721 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'persistentEntities'
2022-10-19 13:20:16.960 TRACE 705721 --- [nio-8080-exec-6] .PrePostAnnotationSecurityMetadataSource : Looking for Pre/Post annotations for method 'save' on target class 'class com.sun.proxy.$Proxy552'
2022-10-19 13:20:16.961 DEBUG 705721 --- [nio-8080-exec-6] .PrePostAnnotationSecurityMetadataSource : #org.springframework.security.access.prepost.PreAuthorize(value=hasAuthority('ROLE_ADMIN') or (#category.businessAccount.id == principal.businessAccountId && hasAuthority('MODULE_FINANCE_AND_ACCOUNTING_WRITE'))) found on specific method: public final com.springboot.api.entities.Category com.sun.proxy.$Proxy552.save(com.springboot.api.entities.Category)
2022-10-19 13:20:16.961 DEBUG 705721 --- [nio-8080-exec-6] m.DelegatingMethodSecurityMetadataSource : Caching method [CacheKey[com.sun.proxy.$Proxy552; public abstract com.springboot.api.entities.Category com.springboot.api.repositories.CategoryRepository.save(com.springboot.api.entities.Category)]] with attributes [[authorize: 'hasAuthority('ROLE_ADMIN') or (#category.businessAccount.id == principal.businessAccountId && hasAuthority('MODULE_FINANCE_AND_ACCOUNTING_WRITE'))', filter: 'null', filterTarget: 'null']]
2022-10-19 13:20:16.972 TRACE 705721 --- [nio-8080-exec-6] .PrePostAnnotationSecurityMetadataSource : Looking for Pre/Post annotations for method 'save' on target class 'class org.springframework.data.jpa.repository.support.SimpleJpaRepository'
2022-10-19 13:20:16.974 DEBUG 705721 --- [nio-8080-exec-6] .PrePostAnnotationSecurityMetadataSource : #org.springframework.security.access.prepost.PreAuthorize(value=hasAuthority('ROLE_ADMIN') or (#category.businessAccount.id == principal.businessAccountId && hasAuthority('MODULE_FINANCE_AND_ACCOUNTING_WRITE'))) found on specific method: public abstract com.springboot.api.entities.Category com.springboot.api.repositories.CategoryRepository.save(com.springboot.api.entities.Category)
...
2022-10-19 13:20:16.975 DEBUG 705721 --- [nio-8080-exec-6] o.s.s.a.i.a.MethodSecurityInterceptor : Previously Authenticated: org.springframework.security.authentication.UsernamePasswordAuthenticationToken#5ebb3b09: Principal: com.springboot.api.security.JwtUser#37c7e936; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails#b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_OPERATOR, MODULE_ACCOUNTS_MANAGEMENT_READ, MODULE_USERS_MANAGEMENT_READ, MODULE_HUMAN_RESOURCE_READ, MODULE_SALES_AND_MARKETING_READ, MODULE_PURCHASE_READ, MODULE_FINANCE_AND_ACCOUNTING_READ, MODULE_CUSTOMERS_RELATIONSHIP_MANAGEMENT_READ
2022-10-19 13:20:16.992 DEBUG 705721 --- [nio-8080-exec-6] o.s.s.a.v.AffirmativeBased : Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter#261e06ac, returned: -1
2022-10-19 13:20:16.992 DEBUG 705721 --- [nio-8080-exec-6] o.s.s.a.v.AffirmativeBased : Voter: org.springframework.security.access.annotation.Jsr250Voter#2b59105d, returned: 0
2022-10-19 13:20:16.992 DEBUG 705721 --- [nio-8080-exec-6] o.s.s.a.v.AffirmativeBased : Voter: org.springframework.security.access.vote.RoleVoter#ef6ea6b, returned: 0
2022-10-19 13:20:16.992 DEBUG 705721 --- [nio-8080-exec-6] o.s.s.a.v.AffirmativeBased : Voter: org.springframework.security.access.vote.AuthenticatedVoter#1e3b3303, returned: 0
2022-10-19 13:20:17.025 TRACE 705721 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'delegatingApplicationListener'
2022-10-19 13:20:17.025 TRACE 705721 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
2022-10-19 13:20:17.025 TRACE 705721 --- [nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'liveReloadServerEventListener'
2022-10-19 13:20:17.036 DEBUG 705721 --- [nio-8080-exec-6] .m.m.a.ExceptionHandlerExceptionResolver : Using #ExceptionHandler com.springboot.api.controllers.ExceptionHandlerController#handleAccessDeniedException(AccessDeniedException, WebRequest)
2022-10-19 13:20:17.036 TRACE 705721 --- [nio-8080-exec-6] .w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: [org.springframework.security.access.AccessDeniedException: Access is denied, ServletWebRequest: uri=/categories/13122;client=0:0:0:0:0:0:0:1;user=jo#eriti.com.br]
2022-10-19 13:20:17.037 ERROR 705721 --- [nio-8080-exec-6] c.s.a.c.ExceptionHandlerController : Access is denied
org.springframework.security.access.AccessDeniedException: Access is denied
at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84) ~[spring-security-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233) ~[spring-security-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:65) ~[spring-security-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
Here is my Repository
#PreAuthorize("hasAuthority('ROLE_ADMIN')")
#Transactional(readOnly=true)
#RepositoryRestResource(collectionResourceRel = "categories", path = "categories")
public interface CategoryRepository extends PagingAndSortingRepository<Category, Long> {
#Transactional(readOnly=false)
#PreAuthorize("hasAuthority('ROLE_ADMIN') or (#category.businessAccount.id == principal.businessAccountId && "
+ "hasAuthority('MODULE_FINANCE_AND_ACCOUNTING_WRITE'))")
#Override
<S extends Category> S save(#Param("category") S file);
...
}
Here is my EventHandler
#Component
#RepositoryEventHandler(Category.class)
public class CategoryEventHandler {
#Autowired
private CategoryRepository categoryRepository;
#Autowired
private MessageSource messageSource;
#HandleBeforeCreate
public void handleEntityAccountBeforeCreate(Category category) throws Exception {
...
}
...
}
Here is my Security Config
...
#Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers(AUTH_WHITELIST).permitAll()
.and()
.authorizeRequests()
.anyRequest()
.authenticated();
httpSecurity.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
httpSecurity.headers().cacheControl();
}
...

SpringBoot Transactional Propagation REQUIRES_NEW doesn't create new Transaction

I have the following scenario:
#Service
public class ServiceA {
#Autowired private ServiceB serviceB;
public void runA(){
serviceB.runB()
}
}
#Service
public class ServiceB {
#Autowired private ServiceC serviceC;
#Transactional
public void runB(){
serviceC.runC()
...rest of the logic
}
}
#Service
public class ServiceC {
#Autowired private TestRepository testRepository;
#Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean runC(){
Optional<TestEntity> testEntityOptional = testRepository.findByKeyAndType("Key", "Type");
if(testEntityOptional.isPresent()) {
testEntityOptional.get().setActive(true);
return true;
}
return false;
}
}
#Transactional
public interface TestRepository
extends JpaRepository<TestEntity, Integer>, JpaSpecificationExecutor<TestEntity> {
#Lock(LockModeType.PESSIMISTIC_WRITE)
#QueryHints({#QueryHint(name = "javax.persistence.lock.timeout", value = "5000")})
Optional<TestEntity> findByKeyAndType(#NotNull String key, #NotNull String type);
}
I expect next flow:
ServiceA.runA() invokes ServiceB.runB()
ServiceB.runB() opens TRANSACTION_1 (or use transaction if it's opened before) as default propagation is REQUIRED
ServiceB.runB() invokes ServiceC.runC()
ServiceC.runC() opens TRANSACTION_2 because propagation is REQUIRED_NEW
ServiceC.runC() invokes TestRepository.findByKeyAndType() to fetch testEntity by some criteria
TestRepository.findByKeyAndType() return record from DB which match the criteria and lock it for read/update
ServiceB.runC() process the record
ServiceB.runC() returns value and TRANSACTION_2 is committed and so lock released
ServiceB.runB() returns and TRANSACTION_1 is committed
But from my testing this is not the case. It seams that ServiceC.runC() do not create new transaction (TRANSACTION_2) even propagation REQUIRED_NEW is set (or it do not commit it at the return), and lock is released only when ServiceB.runB() returns (when TRANSACTION_1 is committed)
Do anyone see what I am doing wrong here? Is this normal behavior of SpringBoot?
Also the lock timeout doesn't work:
I am using Postgress v10 for DB where lock_timeout is set to "0".
So it looks like #QueryHints({#QueryHint(name = "javax.persistence.lock.timeout", value = "5000")}) doesn't work as once record is locked, the other transaction which try to read the record hangs for a while until the record is unlocked
Once I enabled logging.level.org.springframework.orm.jpa.JpaTransactionManager=DEBUG, this is what I see. It includes suspension and resumption.
Is your transaction manager also JpaTransactionManager?
2020-06-30 01:11:53.239 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [com.example.accessingdatajpa.BlogService.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2020-06-30 01:11:57.532 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(1968179698<open>)] for JPA transaction
2020-06-30 01:11:57.538 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#7f2542f]
2020-06-30 01:12:02.432 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1968179698<open>)] for JPA transaction
2020-06-30 01:12:04.032 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Suspending current transaction, creating new transaction with name [com.example.accessingdatajpa.Service2.save]
2020-06-30 01:12:06.915 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(2143659352<open>)] for JPA transaction
2020-06-30 01:12:06.916 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#42fd8f2f]
2020-06-30 01:12:10.196 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(2143659352<open>)] for JPA transaction
2020-06-30 01:12:11.489 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Participating in existing transaction
2020-06-30 01:12:12.227 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-06-30 01:12:13.082 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(2143659352<open>)]
2020-06-30 01:12:13.109 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(2143659352<open>)] after transaction
2020-06-30 01:12:13.110 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Resuming suspended transaction after completion of inner transaction
2020-06-30 01:12:16.409 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2020-06-30 01:12:17.541 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1968179698<open>)]
2020-06-30 01:12:17.542 DEBUG 47133 --- [ main] o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(1968179698<open>)] after transaction

Spring - Same entity detached on the #EventListener but attached in the #Service class

I have following classes in my Spring application: TaskService and DevStartup.
When application starts DevStartup is run, but the Tag("Home") is seen as detached entity on tasksRepository.save(task) which throws detached entity exception during startup.
#Component
#AllArgsConstructor
#Slf4j
#Profile("dev")
public class DevStartup {
private final TagsService tagsService;
private final TagsRepository tagsRepository;
private final TasksRepository tasksRepository;
private final Clock clock;
private final EntityManager entityManager;
#EventListener(ApplicationReadyEvent.class)
public void initializeApplication() {
insertTags();
insertTasks();
}
private void insertTags() {
List<Tag> tags = Arrays.asList(
new Tag("Home")
);
tagsRepository.saveAll(tags);
}
private void insertTasks() {
Task task = new Task("Run a webinar", "Zoom.us", clock.time());
Set<Tag> tagsForTask = Stream.of("Home")
.map(tag -> tagsService.findByName(tag).orElseGet(() -> new Tag(tag)))
.collect(Collectors.toSet());
task.addTags(tagsForTask);
tasksRepository.save(task); // ERROR -> Tag("Home") Entity Detached!!!!!
}
}
At the same time I'm having exact code in the TaskService class and I call it with the same arguments from my REST Controller.
addTask("Task title", "Task description", Stream.of("Home").collect(toSet());
And this time, the Tag("Home") entity is attached
#Service
#RequiredArgsConstructor
public class TasksService {
private final StorageService storageService;
private final TasksRepository tasksRepository;
private final TagsService tagsService;
private final Clock clock;
private final EntityManager entityManager;
public Task addTask(String title, String description, Set<String> tags) {
Task task = new Task(
title,
description,
clock.time()
);
Set<Tag> tagsForTask = tags.stream()
.map(tag -> tagsService.findByName(tag).orElseGet(() -> new Tag(tag)))
.collect(Collectors.toSet());
task.addTags(tagsForTask);
tasksRepository.save(task); // OK -> Tag("Home") Entity Attached
return task;
}
// ...
}
What is the difference between those two and why entity is detached in one case and attached in the other?
I am using Spring Boot 2.1.9 with Hibernate 5 and JPA (Spring Data JPA project).
TagsService.findByName() is just calling TagsRepository.findByNameContainingIgnoreCase:
public interface TagsRepository extends JpaRepository<Tag, Long> {
Optional<Tag> findByNameContainingIgnoreCase(String name);
}
Update
Here are the trace logs from DevStartup. I can spot that session is closed right after fetching the Tag from TagService, and then opened again for saving Task (this is why I'm getting the detached entity exception).
2020-01-25 23:06:46.774 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Automatically flushing session
2020-01-25 23:06:46.778 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : SessionImpl#afterTransactionCompletion(successful=true, delayed=false)
2020-01-25 23:06:46.779 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Closing session [d8094673-13fd-4b7e-af38-4aa01afbcaf7]
2020-01-25 23:06:46.789 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Opened Session [d2c0c551-6523-466f-ab07-a8c1455c62a4] at timestamp: 1579990006789
2020-01-25 23:06:46.848 DEBUG 33093 --- [ restartedMain] org.hibernate.SQL : select tag0_.id as id1_2_, tag0_.name as name2_2_ from tag tag0_ where upper(tag0_.name) like upper(?) escape ?
Hibernate: select tag0_.id as id1_2_, tag0_.name as name2_2_ from tag tag0_ where upper(tag0_.name) like upper(?) escape ?
2020-01-25 23:06:46.850 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%Home%]
2020-01-25 23:06:46.850 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CHAR] - [\]
2020-01-25 23:06:46.855 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Closing session [d2c0c551-6523-466f-ab07-a8c1455c62a4]
2020-01-25 23:06:46.860 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Opened Session [6caeb288-a608-4aa7-a5f9-091c69900815] at timestamp: 1579990006860
2020-01-25 23:06:46.867 DEBUG 33093 --- [ restartedMain] org.hibernate.SQL : insert into task (id, uuid, created_at, description, title) values (null, ?, ?, ?, ?)
Hibernate: insert into task (id, uuid, created_at, description, title) values (null, ?, ?, ?, ?)
2020-01-25 23:06:46.868 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [fc9c993b-eccf-45ff-b49a-12498b6e62eb]
2020-01-25 23:06:46.868 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [TIMESTAMP] - [2020-01-25T23:06:46.785455]
2020-01-25 23:06:46.870 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [Zoom.us]
2020-01-25 23:06:46.872 TRACE 33093 --- [ restartedMain] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [Run a webinar]
2020-01-25 23:06:46.879 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : SessionImpl#afterTransactionCompletion(successful=false, delayed=false)
2020-01-25 23:06:46.880 TRACE 33093 --- [ restartedMain] org.hibernate.internal.SessionImpl : Closing session [6caeb288-a608-4aa7-a5f9-091c69900815]
2020-01-25 23:06:46.900 ERROR 33093 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
Below are the logs when running code from TaskService. The session is not closed between fetching tags and saving tasks.
2020-01-25 23:10:24.966 TRACE 33194 --- [ restartedMain] org.hibernate.internal.SessionImpl : Closing session [f3ea3806-3c65-4269-81b4-ba8bc1abf2af]
2020-01-25 23:10:55.518 INFO 33194 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-01-25 23:10:55.519 INFO 33194 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-01-25 23:10:55.533 INFO 33194 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 14 ms
2020-01-25 23:10:55.553 TRACE 33194 --- [nio-8080-exec-1] org.hibernate.internal.SessionImpl : Opened Session [61d3d232-2d92-4002-8e4c-cedb0278a2e9] at timestamp: 1579990255552
2020-01-25 23:10:55.858 INFO 33194 --- [nio-8080-exec-1] p.s.t.tasks.boundary.TasksController : Storing new task: CreateTaskRequest(title=Dokończyć Moduł 8, description=Jpa i Hibernate cz. 2, attachmentComment=null, tags=[Home])
2020-01-25 23:10:55.914 DEBUG 33194 --- [nio-8080-exec-1] org.hibernate.SQL : select tag0_.id as id1_2_, tag0_.name as name2_2_ from tag tag0_ where upper(tag0_.name) like upper(?) escape ?
Hibernate: select tag0_.id as id1_2_, tag0_.name as name2_2_ from tag tag0_ where upper(tag0_.name) like upper(?) escape ?
2020-01-25 23:10:55.920 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%Home%]
2020-01-25 23:10:55.920 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [CHAR] - [\]
2020-01-25 23:10:59.218 DEBUG 33194 --- [nio-8080-exec-1] org.hibernate.SQL : insert into task (id, uuid, created_at, description, title) values (null, ?, ?, ?, ?)
Hibernate: insert into task (id, uuid, created_at, description, title) values (null, ?, ?, ?, ?)
2020-01-25 23:10:59.218 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [bac8dacb-9424-4c6e-9a3a-860973ebc350]
2020-01-25 23:10:59.219 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [TIMESTAMP] - [2020-01-25T23:10:55.878153]
2020-01-25 23:10:59.223 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [Jpa i Hibernate cz. 2]
2020-01-25 23:10:59.224 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [Dokończyć Moduł 8]
2020-01-25 23:10:59.244 TRACE 33194 --- [nio-8080-exec-1] org.hibernate.internal.SessionImpl : SessionImpl#beforeTransactionCompletion()
2020-01-25 23:10:59.244 TRACE 33194 --- [nio-8080-exec-1] org.hibernate.internal.SessionImpl : Automatically flushing session
2020-01-25 23:10:59.262 DEBUG 33194 --- [nio-8080-exec-1] org.hibernate.SQL : insert into tags_tasks (task_id, tag_id) values (?, ?)
Hibernate: insert into tags_tasks (task_id, tag_id) values (?, ?)
2020-01-25 23:10:59.263 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [1]
2020-01-25 23:10:59.264 TRACE 33194 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [BIGINT] - [1]
2020-01-25 23:10:59.273 TRACE 33194 --- [nio-8080-exec-1] org.hibernate.internal.SessionImpl : SessionImpl#afterTransactionCompletion(successful=true, delayed=false)
Most likely, you have Open Session In View enabled
If you are running a web application, Spring Boot by default registers OpenEntityManagerInViewInterceptor to apply the “Open EntityManager in View” pattern, to allow for lazy loading in web views. If you do not want this behavior, you should set spring.jpa.open-in-view to false in your application.properties.
This will open the session when request starts and and closes it after the request processing is done. The interceptor is run for web request, but not in case of ApplicationReadyEvent event listener.
You may want to use #Transactional to extend the lifetime of the session when you are not relying on open session in view. See https://stackoverflow.com/a/24713402/1570854:
In Spring, there is a one-to-one correspondence between the business transaction demarcated by #Transactional, and the hibernate Session.
That is, when a business transaction is begun by invoking a #Transactional method, the hibernate session is created (a TransactionManager may delay the actual creation until the session is first used). Once that method completes, the business transaction is committed or rolled back, which closes the hibernate session.
Many consider open session in view to be an anti-pattern: https://vladmihalcea.com/the-open-session-in-view-anti-pattern/

spring-boot hangs a while during start

One of our spring-boot applications using camel hangs on start for anywhere between 1 to 5 minutes, but not consistently.
The production environment the application runs in is the raspberry pi, running openJDK. We are unable to reproduce the issue on development machines.
Even on the pis however, the issue is exceedingly rare and seems to happen only on some. In fact we currently only have one in the field where this is a consistent problem, but there it's somewhat of a critical issue due to it being solar powered. The problem has been observed once before on another Pi, where it wasn't critical, and not 100% consistent, and went away again after a while.
Unfortunately we cannot test the pi for hardware issues. Travelling costs would be significant, so before we have no other option left we cannot afford to go and replace it with the possibility that not even that will fix the issue. Also, the pis syslog shows no suspicious activity at all during and around the time the hang happens.
This just to explain why I am posting the question even though a hardware issue cannot be 100% excluded at the moment. We simply need to exclude everything else first.
Now for the actual question: Here is a complete trace (log.level.root = TRACE) of the application at the time the hang occurs. I can provide a complete trace of the startup, but didn't think spamming thousands of lines of logs would help much.I am mostly interested in whether you see anything suspicious. I have looked at these entries for some time and cannot see any hint to the cause of the hang, but my experience with the inner life of spring-boot is very limited.
2019-10-30 08:28:16.090 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' to allow for resolving potential circular references
2019-10-30 08:28:16.091 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Getting BeanInfo for class [org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor]
2019-10-30 08:28:16.106 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Caching PropertyDescriptors for class [org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor]
2019-10-30 08:28:16.107 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'applicationContext' of type [org.springframework.context.ApplicationContext]
2019-10-30 08:28:16.107 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'beanFactory' of type [org.springframework.beans.factory.BeanFactory]
2019-10-30 08:28:16.107 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'beanName' of type [java.lang.String]
2019-10-30 08:28:16.107 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'class' of type [java.lang.Class]
2019-10-30 08:28:16.108 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'embeddedValueResolver' of type [org.springframework.util.StringValueResolver]
2019-10-30 08:28:16.109 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'order' of type [int]
2019-10-30 08:28:16.109 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'scheduledTasks' of type [java.util.Set]
2019-10-30 08:28:16.109 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'scheduler' of type [java.lang.Object]
2019-10-30 08:28:16.185 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
2019-10-30 08:28:16.186 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'persistenceExceptionTranslationPostProcessor'
2019-10-30 08:28:16.186 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'persistenceExceptionTranslationPostProcessor'
2019-10-30 08:28:16.370 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'environment'
2019-10-30 08:28:16.375 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Autowiring by type from bean name 'persistenceExceptionTranslationPostProcessor' via factory method to bean named 'environment'
2019-10-30 08:28:16.379 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'configurationProperties'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'commandLineArgs'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'systemProperties'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'systemEnvironment'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'random'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'applicationConfig: [file:./application.properties]'
2019-10-30 08:28:16.381 TRACE 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'spring.aop.proxy-target-class' in PropertySource 'applicationConfig: [classpath:/application.properties]'
2019-10-30 08:28:16.381 DEBUG 456 --- [main] o.s.c.e.PropertySourcesPropertyResolver : Could not find key 'spring.aop.proxy-target-class' in any property source
2019-10-30 08:28:16.398 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'persistenceExceptionTranslationPostProcessor' to allow for resolving potential circular references
2019-10-30 08:28:16.399 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Getting BeanInfo for class [org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor]
2019-10-30 08:28:16.437 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Caching PropertyDescriptors for class [org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor]
2019-10-30 08:28:16.437 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'beanClassLoader' of type [java.lang.ClassLoader]
2019-10-30 08:28:16.437 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'beanFactory' of type [org.springframework.beans.factory.BeanFactory]
2019-10-30 08:28:16.437 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'beforeExistingAdvisors' of type [boolean]
2019-10-30 08:28:16.438 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'class' of type [java.lang.Class]
2019-10-30 08:28:16.438 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'exposeProxy' of type [boolean]
2019-10-30 08:28:16.439 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'frozen' of type [boolean]
2019-10-30 08:28:16.440 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'opaque' of type [boolean]
2019-10-30 08:28:16.440 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'optimize' of type [boolean]
2019-10-30 08:28:16.441 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'order' of type [int]
2019-10-30 08:28:16.441 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'proxyClassLoader' of type [java.lang.ClassLoader]
2019-10-30 08:28:16.441 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'proxyTargetClass' of type [boolean]
2019-10-30 08:28:16.442 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'repositoryAnnotationType' of type [java.lang.Class]
2019-10-30 08:28:16.507 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'persistenceExceptionTranslationPostProcessor'
2019-10-30 08:28:16.507 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Creating shared instance of singleton bean 'dataSourceInitializerPostProcessor'
2019-10-30 08:28:16.507 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Creating instance of bean 'dataSourceInitializerPostProcessor'
2019-10-30 08:28:16.522 DEBUG 456 --- [main] o.s.b.f.annotation.InjectionMetadata : Registered injected element on class [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor]: AutowiredFieldElement for private org.springframework.beans.factory.BeanFactory org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor.beanFactory
2019-10-30 08:28:16.522 DEBUG 456 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Eagerly caching bean 'dataSourceInitializerPostProcessor' to allow for resolving potential circular references
2019-10-30 08:28:16.522 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Getting BeanInfo for class [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor]
2019-10-30 08:28:16.532 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Caching PropertyDescriptors for class [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerPostProcessor]
2019-10-30 08:28:16.533 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'class' of type [java.lang.Class]
2019-10-30 08:28:16.533 TRACE 456 --- [main] o.s.beans.CachedIntrospectionResults : Found bean property 'order' of type [int]
// Note the significant time jump!
2019-10-30 08:30:16.087 TRACE 454 --- [main] org.apache.sshd.client.SshClient : addSessionListener(SshClient[f66866])[org.apache.sshd.common.session.helpers.SessionTimeoutListener#b50150] registered
2019-10-30 08:30:16.088 TRACE 454 --- [main] .a.s.c.u.t.ThreadUtils$SshdThreadFactory : newThread(java.lang.ThreadGroup[name=main,maxpri=10])[sshd-SshClient[f66866]-timer-thread-1] runnable=java.util.concurrent.ThreadPoolExecutor$Worker#1b986cd[State = -1, empty queue]
2019-10-30 08:30:16.161 TRACE 454 --- [main] o.a.sshd.common.io.nio2.Nio2Connector : Creating Nio2Connector
2019-10-30 08:30:16.162 DEBUG 454 --- [main] o.a.camel.component.ssh.SshProducer : Starting producer: Producer[ssh://root:xxxxxx#192.168.1.1]
2019-10-30 08:30:16.162 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.162 DEBUG 454 --- [main] o.a.camel.component.exec.ExecProducer : Starting producer: Producer[exec://sudo]
2019-10-30 08:30:16.162 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.162 DEBUG 454 --- [main] o.a.camel.component.exec.ExecProducer : Starting producer: Producer[exec://sudo]
2019-10-30 08:30:16.162 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.162 DEBUG 454 --- [main] o.a.c.c.direct.DirectBlockingProducer : Starting producer: Producer[direct://switch-off-camera]
2019-10-30 08:30:16.162 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.163 DEBUG 454 --- [main] o.a.camel.component.seda.SedaProducer : Starting producer: Producer[seda://capture-image]
2019-10-30 08:30:16.163 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.163 DEBUG 454 --- [main] o.a.c.c.direct.DirectBlockingProducer : Starting producer: Producer[direct://switch-off-camera]
2019-10-30 08:30:16.163 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.163 DEBUG 454 --- [main] o.a.camel.component.seda.SedaProducer : Starting producer: Producer[seda://image-queue]
2019-10-30 08:30:16.163 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.163 DEBUG 454 --- [main] o.a.c.c.direct.DirectBlockingProducer : Starting producer: Producer[direct://failed-upload]
2019-10-30 08:30:16.163 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.163 DEBUG 454 --- [main] o.a.c.c.direct.DirectBlockingProducer : Starting producer: Producer[direct://switch-off-camera]
2019-10-30 08:30:16.163 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.164 TRACE 454 --- [main] org.apache.camel.support.ServiceSupport : Starting service
2019-10-30 08:30:16.164 DEBUG 454 --- [main] o.a.camel.component.seda.SedaProducer : Starting producer: Producer[seda://capture-command]
2019-10-30 08:30:16.164 DEBUG 454 --- [main] o.a.camel.spring.SpringCamelContext : Route: route1 >>> EventDrivenConsumerRoute[seda://start-deepsleep -> Pipeline[[Channel[Log(route1)[Starting deep sleep for ${body} seconds]], Channel[SetBody(Simple: sh -c '(sleep 15; io set out0 1; sleep 2; lpm -i ${body})' </dev/null >/dev/null 2>&1 &)], Channel[Log(route1)[Executing SSH command: ${body}]], C
2019-10-30 08:30:16.165 DEBUG 454 --- [main] o.a.camel.spring.SpringCamelContext : Starting consumer (order: 1000) on route: route1
2019-10-30 08:30:16.165 TRACE 454 --- [main] a.c.m.DefaultManagementLifecycleStrategy : Checking whether to register SedaConsumer[seda://start-deepsleep] from route: EventDrivenConsumerRoute[seda://start-deepsleep -> Pipeline[[Channel[Log(route1)[Starting deep sleep for ${body} seconds]], Channel[SetBody(Simple: sh -c '(sleep 15; io set out0 1; sleep 2; lpm -i ${body})' </dev/null >/dev/null 2>&1
2019-10-30 08:30:16.166 DEBUG 454 --- [main] javax.management.mbeanserver : name = org.apache.camel:context=camel-1,type=consumers,name=SedaConsumer(0x1f22f18)
2019-10-30 08:30:16.167 DEBUG 454 --- [main] javax.management.mbeanserver : name = org.apache.camel:context=camel-1,type=consumers,name=SedaConsumer(0x1f22f18)
2019-10-30 08:30:16.167 TRACE 454 --- [main] o.a.c.management.DefaultManagementAgent : Registering MBean with ObjectName: org.apache.camel:context=camel-1,type=consumers,name=SedaConsumer(0x1f22f18)
2019-10-30 08:30:16.168 TRACE 454 --- [main] o.a.c.m.DefaultManagementMBeanAssembler : Assembling MBeanInfo for: org.apache.camel:context=camel-1,type=consumers,name=SedaConsumer(0x1f22f18) from #ManagedResource object: org.apache.camel.management.mbean.ManagedConsumer#8572f0
2019-10-30 08:30:16.168 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from class: class org.apache.camel.management.mbean.ManagedConsumer
2019-10-30 08:30:16.174 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public java.lang.Integer org.apache.camel.management.mbean.ManagedConsumer.getInflightExchanges()
2019-10-30 08:30:16.175 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public org.apache.camel.Consumer org.apache.camel.management.mbean.ManagedConsumer.getConsumer()
2019-10-30 08:30:16.175 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public java.lang.String org.apache.camel.management.mbean.ManagedConsumer.getEndpointUri()
2019-10-30 08:30:16.175 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from sub class: class org.apache.camel.management.mbean.ManagedService
2019-10-30 08:30:16.176 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from class: class org.apache.camel.management.mbean.ManagedService
2019-10-30 08:30:16.180 TRACE 454 --- [ForkJoinPool.commonPool-worker-2] org.apache.camel.util.LRUCache : onRemoval class org.apache.camel.management.mbean.ManagedService -> null
2019-10-30 08:30:16.180 TRACE 454 --- [ForkJoinPool.commonPool-worker-3] org.apache.camel.util.LRUCache : onRemoval interface org.apache.camel.api.management.mbean.ManagedServiceMBean -> null
2019-10-30 08:30:16.180 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public java.lang.String org.apache.camel.management.mbean.ManagedService.getServiceType()
2019-10-30 08:30:16.180 TRACE 454 --- [ForkJoinPool.commonPool-worker-2] org.apache.camel.util.LRUCache : onRemoval class org.apache.camel.management.mbean.ManagedProducer -> null
2019-10-30 08:30:16.181 TRACE 454 --- [ForkJoinPool.commonPool-worker-3] org.apache.camel.util.LRUCache : onRemoval interface org.apache.camel.api.management.mbean.ManagedProducerMBean -> null
2019-10-30 08:30:16.181 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public boolean org.apache.camel.management.mbean.ManagedService.isSupportSuspension()
2019-10-30 08:30:16.182 TRACE 454 --- [ForkJoinPool.commonPool-worker-3] org.apache.camel.util.LRUCache : onRemoval interface org.apache.camel.api.management.ManagedInstance -> null
2019-10-30 08:30:16.182 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public boolean org.apache.camel.management.mbean.ManagedService.isStaticService()
2019-10-30 08:30:16.182 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public void org.apache.camel.management.mbean.ManagedService.setRoute(org.apache.camel.Route)
2019-10-30 08:30:16.182 TRACE 454 --- [main] o.a.camel.management.MBeanInfoAssembler : Extracting attributes and operations from method: public java.lang.String org.apache.camel.management.mbean.ManagedService.getCamelManagementName()
I've marked the gap in time where nothing appears to be happening. Now, there are a few entries in there that I've taken out. The quartz job-store is doing its thing with the h2 database, and a scheduled task by one of our services is already already running. No suspicious things, and we managed to exclude them entirely in some test runs, but it shows that the system as a whole isn't stalled. Spring-boot just seems to be waiting for something before continuing.
I was hoping that somebody more at home with spring-boot might tell me what spring-boot is waiting for in that time based on these logs.
We have also excluded the possibility of wrong logging times (i.e. that the hang isn't actually there, instead the clock jumps), especially since this is a pi.
It may or may not be noteworthy that the hang occurs between camel instantiating the endpoints and camel starting the routes. Usually these are only a second appart, but I'd expect to see some sings of trouble in the log if there would be a hang-up with that.
The problem is that the Pi you are deploying to does not have enough "noise" for the random number generator to start properly. Oracle has a solution for this issue: https://docs.oracle.com/cd/E13209_01/wlcp/wlss30/configwlss/jvmrand.html

DSLContext bean takes several minutes to be created

After incorporating JOOQ into my Spring-Boot application, the internal Tomcat server boot time is more than 5 minutes!
I configured my application with JOOQ like documented on the Spring Boot documentation.
When I enable 'debug' logging you can notice it takes about 5 minutes for creating bean 'dslContext'. It seems that HikariCP is doing some stuff in the background for several minutes. This didn't happen before I configured JOOQ in my application.
Debug logging below:
21:04:59.292 [ main] DEBUG --- Creating shared instance of singleton bean 'dslContext'
21:04:59.292 [ main] DEBUG --- Creating instance of bean 'dslContext'
21:04:59.292 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:04:59.292 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:04:59.292 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:04:59.293 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:04:59.293 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration'
21:04:59.299 [ main] DEBUG --- Creating shared instance of singleton bean 'jooqConfiguration'
21:04:59.300 [ main] DEBUG --- Creating instance of bean 'jooqConfiguration'
21:04:59.300 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:04:59.300 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:04:59.300 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:04:59.300 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:04:59.301 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration'
21:04:59.376 [ main] DEBUG --- Eagerly caching bean 'jooqConfiguration' to allow for resolving potential circular references
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:04:59.386 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:04:59.551 [ main] DEBUG --- Finished creating instance of bean 'jooqConfiguration'
21:04:59.562 [ main] DEBUG --- Autowiring by type from bean name 'dslContext' via factory method to bean named 'jooqConfiguration'
21:04:59.942 [ main] DEBUG --- Eagerly caching bean 'dslContext' to allow for resolving potential circular references
21:05:00.023 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:05:00.023 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:05:00.023 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:05:00.027 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:05:00.027 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.cache.config.internalCacheAdvisor'
21:05:00.027 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.retry.annotation.RetryConfiguration'
21:05:00.027 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
21:05:00.027 [ main] DEBUG --- Returning cached instance of singleton bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor'
21:05:20.109 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:05:50.113 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:06:20.114 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:06:50.116 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:07:13.126 [Engine[Tomcat]]] DEBUG --- Start expire sessions StandardManager at 1520539633101 sessioncount 0
21:07:13.128 [Engine[Tomcat]]] DEBUG --- End expire sessions StandardManager processingTime 27 expired sessions: 0
21:07:20.118 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:07:50.121 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:08:20.124 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:08:50.126 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:09:20.130 [iCP housekeeper] DEBUG --- SpringBootHikariCP - Pool stats (total=3, active=0, idle=3, waiting=0)
21:09:43.440 [ main] DEBUG --- Finished creating instance of bean 'dslContext'
Any ideas...?
After taking a thread dump it became clear that the problem is caused by aspectjweaver.
More info can be found here.
By excluding org.jooq in pointcut matching the problem is solved.

Resources