javax.persistence.RollbackException: Transaction marked as rollbackOnly Ask
来源:互联网 发布:ubuntu wget安装 编辑:程序博客网 时间:2024/05/16 18:29
javax.persistence.RollbackException: Transaction marked as rollbackOnly
with Spring MVC. I have a method for get the game and update but when it goes to update it gives an error, this is the code:
HomeController.class
@Transactional@RequestMapping(value = "/partida/{idPartida}", method = RequestMethod.GET)public String getPartida(@PathVariable("idPartida") long idPartida, Model model) throws IOException { Partida p = ServicioAplicacionPartida.getPartida(entityManager, idPartida); if (p.getJson() == null) { p.inicializarPartida(entityManager); ServicioAplicacionPartida.update(entityManager, p); }
GameDAO.class
@Transactionalpublic static Partida update(EntityManager entityManager, Partida p) { try { Query q = entityManager.createNativeQuery("update Partida p SET p.json=:json where p.id=:id"); q.setParameter("json", p.getJson()); q.setParameter("id", p.getId()); q.executeUpdate(); return entityManager.find(Partida.class, p.getId()); } catch (Exception e) { e.printStackTrace(); return null; }}
The error occurs when the line "q.executeUdate()" is executed, here it is:
javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute statement
And this is the server error:
Estado HTTP 500 - Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
What can i do to fix it?
You have annotated controller and DAO methods as @Transactional, it is not correct as @Transactional can be inherited to the inner methods. Usually transaction should start at service layer.
Try adding these parameters to @Transactional annotation and remove it from either Controller or DAO.:
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Exception.class)
and try:
propagation = Propagation.REQUIRES_NEW
- javax.persistence.RollbackException: Transaction marked as rollbackOnly Ask
- javax.persistence.RollbackException: Transaction marked as rollbackOnly异常出现的原因以及避免方法
- 解决Could not commit JPA transaction RollbackException: Transaction marked as rollbackOnly
- 解决Could not commit JPA transaction RollbackException: Transaction marked as rollbackOnly
- javax.transaction.RollbackException翻译
- nested exception is javax.persistence.RollbackException: Error while commiting the transaction
- JPA出现Transaction marked as rollback only异常 总结
- javax.persistence.TransactionRequiredException: no transaction is in progress
- javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available..
- javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available f
- javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available f
- [原]在Oracle SOASUITE 10g Register ESB 报“The exception reported is: "javax.transaction.RollbackException: Timed out”问题的解决办法
- Transaction rolled back because it has been marked as rollback-only
- spring事务 Transaction rolled back because it has been marked as rollback-only
- Transaction has been rolled back because it has been marked as rollback
- Transaction rolled back because it has been marked as rollback-only
- Transaction rolled back because it has been marked as rollback-only
- Transaction rolled back because it has been marked as rollback-only
- 《Springboot极简教程》SpringBoot热部署应用Developer tools
- Linux的scp命令
- 《Springboot极简教程》SpringBoot配置文件PropertySourcesPlaceholderConfigurer
- 查看artisan有效的命令
- 《Java核心技术》java中的{},static{}的代码块
- javax.persistence.RollbackException: Transaction marked as rollbackOnly Ask
- 关于Spring的事务Transactional,锁同步,并发线程
- RESTFeel: 一个企业级的API管理&测试平台。RESTFeel帮助你设计、开发、测试您的API
- DFiddler:A HTTP Packets Listener一个简易版的手机端的Fiddler。
- 六条“黑客伦理”(hacker ethic)
- 黑客的价值观
- 《Springboot极简教程》SpringBoot plus Mongodb开发企业级restfeel接口测试平台
- wait-notify 实现多线程交叉备份
- Myeclipse2015把web项目添加至tomcat中,添加列表中却没有想要添加的项目