No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available
参考地址:
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)
作者: lost blog
出处: http://www.cnblogs.com/JAYIT/
关于作者:专注服务器端开发
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接 如有问题, 可邮件(sawyershaw@qq.com)咨询.