micronaut 4 org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread

103 Views Asked by At

After I upgraded my project to micronaut 4 I am getting the error:

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread

when calling: getLoadSearchDataRequests

Repo class:

import io.micronaut.aop.Introduction
import io.micronaut.context.annotation.Type
import io.micronaut.data.annotation.Repository
import io.micronaut.data.runtime.intercept.DataIntroductionAdvice
import io.micronaut.transaction.annotation.Transactional
import jakarta.inject.Singleton

@Repository(ContractLaneConstants.SCHEMA)
@Transactional(ContractLaneConstants.SCHEMA)
@Introduction
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@Type(DataIntroductionAdvice::class)
@Singleton
annotation class ContractLaneRepositoryAnnotation

@ContractLaneRepositoryAnnotation
abstract class ContractLaneRepository(
    @Named("contractlane") val entityManager: EntityManager,
) : JpaRepository<ContractLane, UUID> {

    fun getLoadSearchDataRequests(): Set<LoadSearchDataRequest> {
        val queryString = """
            SELECT 
                NEW com.arrivelogistics.bulkpricing.commons.loadservice.LoadSearchDataRequest(customerId, min(startDate), max(endDate)) 
            from ContractLane
            group by customerId
         """.trimIndent()

        val query = entityManager.createQuery(queryString, LoadSearchDataRequest::class.java)
        return query.resultList.toSet()
    }
}

Stacktrace:

Could not obtain transaction-synchronized Session for current thread
Caused by: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
        at app//io.micronaut.transaction.hibernate.MicronautSessionContext.currentSession(MicronautSessionContext.java:61)
        at app//org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:603)
        at app//io.micronaut.configuration.hibernate.jpa.TransactionalSessionInterceptor.intercept(TransactionalSessionInterceptor.java:62)
        at app//io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
        at app//io.micronaut.configuration.hibernate.jpa.TransactionalSession$Intercepted.createQuery(Unknown Source)
        at app//com.arrivelogistics.bulkpricing.contractlane.persistence.repository.ContractLaneRepository.getLoadSearchDataRequests(ContractLaneRepository.kt:127)
0

There are 0 best solutions below