【问题标题】:Nested transaction in Spring app with JPA (postgres)使用 JPA(postgres)在 Spring 应用程序中嵌套事务
【发布时间】:2016-10-21 23:39:29
【问题描述】:

是否可以使用 postgresPROPAGATION_NESTED 与 JPA 一起包含在 @Transactional() 中?我得到:

org.springframework.transaction.NestedTransactionNotSupportedException:
JpaDialect does not support savepoints - check your JPA provider's capabilities

我试过了:

@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory()
                .getObject());
    transactionManager.setNestedTransactionAllowed(true);
    return transactionManager;
}

但没有成功。

【问题讨论】:

  • 您使用的是哪种 JPA 实现?

标签: java spring postgresql jpa transactions


【解决方案1】:

我假设您正在使用 Hibernate。 Hibernate 无法进行嵌套事务。

在下面的代码摘录中,spring 设置了 savePointManager。但是在 Hibernate 中没有实现SavepointManager 的类。

【讨论】:

  • 是的,我确实使用 Hibernate。啊,太糟糕了。假设我将从 Hibernate 转移到其他东西
【解决方案2】:

savepointAllowed 为真,表示事务管理器允许嵌套事务。但是JpaDialect 不支持保存点。

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    相关资源
    最近更新 更多