无法在micronaut cli应用程序的多线程中获取当前线程的事务同步会话

kcrjzv8t  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(278)

环境:
操作系统:windows 10
jdk版本:11.0.7
micronaut版本:2.5.7
数据库:oracle r12(我猜)
项目:https://github.com/wureka/cli-multithread-jpa
我的项目是用micronaut cli应用程序构建的,并在多线程中运行。因为我的sql是以编程方式构建的,所以我需要entitymanager对象来执行本机sql。
当线程 TestRunner 运行时,一旦entitymanager启动,就会出现以下错误:

08:43:13.514 [main] INFO  DefaultEnvironment - Established active environments: [cli]
08:43:14.107 [main] INFO  HikariDataSource - HikariPool-1 - Starting...
08:43:15.887 [main] INFO  HikariDataSource - HikariPool-1 - Start completed.
08:43:15.893 [main] INFO  Version - HHH000412: Hibernate ORM core version 5.4.24.Final
08:43:16.009 [main] INFO  Version - HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
08:43:16.116 [main] INFO  Dialect - HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
08:43:17.231 [Thread-1] INFO  TestRunner - Thread-1: starts ..........
Exception in thread "Thread-1" org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
    at io.micronaut.transaction.hibernate5.MicronautSessionContext.currentSession(MicronautSessionContext.java:100)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:479)
    at io.micronaut.configuration.hibernate.jpa.TransactionalSessionInterceptor.intercept(TransactionalSessionInterceptor.java:56)
    at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:96)
    at io.micronaut.configuration.hibernate.jpa.TransactionalSession$Intercepted.getTransaction(Unknown Source)
    at com.example.repository.AbstractProcessExcpRepository.deleteProcessExcpsInOneStmt1(AbstractProcessExcpRepository.java:59)
    at com.example.runner.TestRunner.run(TestRunner.java:27)
    at java.base/java.lang.Thread.run(Thread.java:834)
08:43:18.239 [main] INFO  MainController - 1. Wait test result

但如果我跑 AbstractProcessExcpRepository 在主线程中,这样就可以了。那么,您能告诉我如何让CRUDEPository在多线程中工作吗?
谢谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题