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
相關文章
相關標籤/搜索