![](/img/trans.png)
[英]Spring Hibernate LazyInitializationException on @Transactional
[英]Spring @Transactional makes problems in Hibernate
我有一個Play項目,其中使用帶有spring @Transactional批注的以下方法:
@Autowired
Home home;
@Transactional
public Result update() {
try {
JsonNode jsonNode = request().body().asJson();
User user = home.updateFromJsonString(jsonNode.toString());
return ok("Updated successfully.");
} catch (Exception e){
return badRequest("Error updating");
}
}
updateFromJsonString方法位於另一個項目中,在此項目中它使用hibernate更改sql表。 問題是當缺少@Transactional批注時,此“更新”方法可以正常工作,但是當它存在時,出現以下異常:
[error] o.h.e.j.s.SqlExceptionHelper - Duplicate entry '1-10' for key 'PRIMARY'
[error] play - Cannot invoke the action, eventually got an error: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.
exception.ConstraintViolationException: could not execute statement
任何想法是什么問題,以及為什么@Transactional會導致此錯誤?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.