micronaut-sql
micronaut-sql copied to clipboard
Micronaut SQL Hibernate Maven fails with Could not obtain transaction-synchronized Session for current thread
Steps to reproduce:
clone https://github.com/grails-core-issues-forks/micronaut-sql-1156
cd ../micronaut-jpa-hibernate-maven-java
./mvnw verify
You will get:
18:50:44.274 [io-executor-thread-1] ERROR i.m.http.server.RouteExecutor - Unexpected error occurred: Could not obtain transaction-synchronized Session for current thread
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at io.micronaut.transaction.hibernate.MicronautSessionContext.currentSession(MicronautSessionContext.java:61)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:599)
at io.micronaut.configuration.hibernate.jpa.TransactionalSessionInterceptor.intercept(TransactionalSessionInterceptor.java:62)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
at io.micronaut.configuration.hibernate.jpa.TransactionalSession$Intercepted.persist(Unknown Source)
at example.micronaut.GenreRepositoryImpl.save(GenreRepositoryImpl.java:40)
The same application works with Gradle.
cd micronaut-jpa-hibernate-gradle-java
./gradlew test
@dstepanov do you know what it is going on?
In maven, context propagation does not have transactions stored. Looks like adding this dependency to maven annotation processor
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>${micronaut.data.version}</version>
</path>
fixes the issue. The difference between gradle and maven is that gradle automatically adds micronaut-data-processor (which causes issue in https://github.com/micronaut-projects/micronaut-sql/issues/1157). Apparently it is needed for transaction handling via context propagation, but again @dstepanov probably knows why.
That's coming from the Gradle plugin, which adds the processor when there is any kind of -data
dependency.
I see, but since data-tx-hibernate apparently needs data-processor then it should be added as dependency there so this issue wouldn't appear in micronaut-sql?
It only needs it to remap the Jakarta transactional annotation. I think the solution should be to not reference enums in the metadata.
This is different issue. Transactions are not stored/found in context propagation if there is no data-processor dependency which is what we have with Maven.
Ah right. Disregard the last sentence, but the issue is that we remap different TX annotations to an internal one
Checked with 4.3.2 and this still fails...
What's the solution here? We could add the data-processor to the annotation processor paths as specified here in starter?
Than that will trigger this issue https://github.com/micronaut-projects/micronaut-sql/issues/1157 😞