如何在提交或回滚中捕获TransactionException

时间:2017-07-07 08:40:00

标签: java spring hibernate spring-boot transactions

我在具有@Transactional注释的REST API服务中有方法。即使数据库已断开连接,此方法也应抛出MyException

但是当事务执行commit或rollback时,如果数据库断开连接,它将抛出TransactionException。如何在这些情况下抓住TransactionException投掷MyException

@Transactional(readOnly = true)
public List<RoomType> getRoomTypeList() throws MyException {
        return serviceImpl.getRoomTypeList();
}

这是stacktrace:

Caused by: org.hibernate.TransactionException: unable to rollback against JDBC connection
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:167) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:211) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
    ... 99 common frames omitted
Caused by: java.sql.SQLRecoverableException: No more data to read from socket

0 个答案:

没有答案