菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
169
0

No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available

原创
05/13 14:22
阅读数 29423
参考地址:
http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/config/EnableJpaRepositories.html#enableDefaultTransactions--
public abstract boolean enableDefaultTransactions
Configures whether to enable default transactions for Spring Data JPA repositories. Defaults to true. If disabled, repositories must be used behind a facade that's configuring transactions (e.g. using Spring's annotation driven transaction facilities) or repository methods have to be used to demarcate transactions.
Returns:
whether to enable default transactions, defaults to true.
Default:
true
原来是在spring配置文件中关闭了jpa默认的事务管理机制
<jpa:repositories base-package="com.xx.order"
		enable-default-transactions="false" />

 需要手动开启,所以,用spring的annotation在方法或类里面开启------------------(用@Transactional)

发表评论

0/200
169 点赞
0 评论
收藏