Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 事务性注释在spring boot 2.1.3中不起作用_Java_Spring_Hibernate_Spring Boot_Kotlin - Fatal编程技术网

Java 事务性注释在spring boot 2.1.3中不起作用

Java 事务性注释在spring boot 2.1.3中不起作用,java,spring,hibernate,spring-boot,kotlin,Java,Spring,Hibernate,Spring Boot,Kotlin,@Transactional注释在springboot hibernate项目中对我不起作用。我正在使用注释配置,我已经对其进行了以下配置。我曾尝试在服务层和dao层的方法和类名上使用@Transactional,但没有成功。我认为事务管理器配置存在一些问题,但我无法确定如何在我的应用程序中配置事务管理器 应用程序属性 #spring configuration spring.jpa.show-sql = true #spring.jpa.hibernate.naming.physical-st

@Transactional
注释在springboot hibernate项目中对我不起作用。我正在使用注释配置,我已经对其进行了以下配置。我曾尝试在服务层和dao层的方法和类名上使用
@Transactional
,但没有成功。我认为事务管理器配置存在一些问题,但我无法确定如何在我的应用程序中配置事务管理器

应用程序属性

#spring configuration
spring.jpa.show-sql = true
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext

服务

@Override
    @Transactional
    public void deleteSMS(String id) {
        smsDao.deleteSMS(id);
    }
我正在使用SpringBoot2.1.3和hibernate。我已如上所述配置entitymanagerfactory,并使用以下命令获取会话

session = entityManagerFactory.unwrap(SessionFactory.class).openSession();

但是
@Transactional
不起作用

您正在
@Transactional
方法内打开一个
会话
。这是错误的,因为当您将方法注释为事务性时,它是在单个会话中调用的,您不需要打开另一个会话。

您正在一个
@transactional
方法中打开一个
会话。这是错误的,因为当您将方法注释为事务性方法时,它是在单个会话中调用的,您不需要打开另一个会话。

我也有同样的问题 我在我的类应用程序中添加了此注释 @EnableTransactionManagement(proxyTargetClass=true)

这是关于我的课堂服务的方法

@事务性(rollboor=Exception.class)

我也有同样的问题 我在我的类应用程序中添加了此注释 @EnableTransactionManagement(proxyTargetClass=true)

这是关于我的课堂服务的方法


@事务(rollboor=Exception.class)

会话工厂需要由spring和AFAIK管理。此外,您只能在事务启动后打开会话。这在逻辑上是错误的,
SessionFactory
需要由spring和AFAIK管理。此外,您只能在事务启动后打开会话。这在逻辑上是错误的我使用getCurrentSession而不是openSession,但是问题仍然没有解决,我认为问题在于事务管理器的初始化。我正在通过展开entityManagerFactory来创建会话对象,但我不知道如何实例化事务管理器。在这种情况下,我使用了getCurrentSession而不是openSession,但问题仍然没有解决,我认为问题在于事务管理器的初始化。我正在通过展开entityManagerFactory来创建会话对象,但在这种情况下,我无法确定如何实例化事务管理器
session = entityManagerFactory.unwrap(SessionFactory.class).openSession();