我在具有@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