Spring+jpaNo transactional EntityManager available

TransactionRequiredException: No transactional EntityManager available

EntityManager执行如下方法(refresh, persist, flush, joinTransaction, remove, merge) 都须要须要事务

if (transactionRequiringMethods.contains(method.getName())) {
	// We need a transactional target now, according to the JPA spec.
	// Otherwise, the operation would get accepted but remain unflushed...
	if (target == null) {
		throw new TransactionRequiredException("No transactional EntityManager available");
	}
}

须要在方法上加上@Transactional
相关文章
相关标签/搜索