博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javax.persistence.RollbackException: Transaction marked as rollbackOnly Ask
阅读量:7070 次
发布时间:2019-06-28

本文共 1975 字,大约阅读时间需要 6 分钟。

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

转载地址:http://gbell.baihongyu.com/

你可能感兴趣的文章
iOS编程修改系统音量
查看>>
当 iOS 游戏开发像做份沙拉那么简单
查看>>
HDOJ2028 ( Lowest Common Multiple Plus ) 【水题,lcm】
查看>>
css--水平居中,垂直居中,自适应宽度
查看>>
Google Map API V3 离线版
查看>>
ZFS与数据去重
查看>>
《敏捷软件开发》学习笔记 第16章 单例模式和MonoState模式
查看>>
PHP拦截器的使用(转)
查看>>
获取GridView控件总列数
查看>>
Vim 中使用cscope
查看>>
HR系统+人脸识别
查看>>
RabbitMQ与AMQP协议详解
查看>>
metronic后台模板学习 -- 所用外部插件列表
查看>>
微软原版SQLHelper类
查看>>
首页设计的可用性和PET
查看>>
mongodb的分布式集群(1、主从复制)
查看>>
http://www.cnblogs.com/yaozhenfa/archive/2015/06/14/4574898.html
查看>>
动态为DropDownList添加Item
查看>>
spring NotWritablePropertyException异常
查看>>
在单页应用中,如何优雅的监听url的变化
查看>>