No EntityManager with actual transaction available for current thread

No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 问题的处理方法

卡了一天的问题终于解决了!!!
如果已经添加了@Transactional注解了以后还是会报这样的错误的话,请添加如下代码:

@Configuration
@EnableTransactionManagement
public class TransadtionConfig implements TransactionManagementConfigurer {

    @PersistenceUnit
    private EntityManagerFactory emf;

    public PlatformTransactionManager annotationDrivenTransactionManager() {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(emf);
        return transactionManager;
    }
}

造成标题中错误的原因是由于,在当前事务中没有可以用的EntityManagerFactory.
但是,具体是什么原因我其实也不太清楚,我也是一枚萌新,还希望路过的大佬指点一下。

知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值