Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micronaut SQL Hibernate Maven fails with Could not obtain transaction-synchronized Session for current thread #1156

Open
sdelamo opened this issue Nov 11, 2023 · 9 comments
Assignees
Labels
type: bug Something isn't working

Comments

@sdelamo
Copy link
Contributor

sdelamo commented Nov 11, 2023

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          
@sdelamo sdelamo added the type: bug Something isn't working label Nov 11, 2023
@sdelamo
Copy link
Contributor Author

sdelamo commented Nov 11, 2023

@dstepanov do you know what it is going on?

@radovanradic
Copy link
Contributor

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 #1157).
Apparently it is needed for transaction handling via context propagation, but again @dstepanov probably knows why.

@dstepanov
Copy link
Contributor

That's coming from the Gradle plugin, which adds the processor when there is any kind of -data dependency.

@radovanradic
Copy link
Contributor

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?

@dstepanov
Copy link
Contributor

It only needs it to remap the Jakarta transactional annotation. I think the solution should be to not reference enums in the metadata.

@radovanradic
Copy link
Contributor

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.

@dstepanov
Copy link
Contributor

Ah right. Disregard the last sentence, but the issue is that we remap different TX annotations to an internal one

@timyates
Copy link
Member

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?

@radovanradic
Copy link
Contributor

Than that will trigger this issue #1157 😞

@sdelamo sdelamo self-assigned this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

4 participants