Spring + Hibernate + JTAプロジェクトで、例外処理を機能させようとしています。次のコードの場合:
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public HandsetManufacturer createHandsetManufacturer(
HandsetManufacturer handsetManufacturer)
throws HandsetManufacturerAlreadyExistsException{
HandsetManufacturer handsetManufacturer2=new HandsetManufacturer();
try {
handsetManufacturerDao.findByUniqueProperty(
HandsetManufacturer.class, NAME_PROPERTY,
handsetManufacturer.getName());
throw new HandsetManufacturerAlreadyExistsException();
} catch (BusinessObjectNotFoundException ignoreMe) {
}
//handsetManufacturer2= handsetManufacturerDao.create(handsetManufacturer);
try{
handsetManufacturer2= handsetManufacturerDao.create(handsetManufacturer);
}catch (JDBCException e) {
System.out.println("::HibernateException::"+e.getSQL());
System.out.println("::HibernateException::"+e.getErrorCode());
System.out.println("::HibernateException::"+e.getSQLState());
System.out.println("::HibernateException::"+e.getSQLException());
System.out.println("::HibernateException::"+e.getMessage());
System.out.println("::HibernateException::"+e.getCause());
throw new TechnicalException(e);
}
return handsetManufacturer2;
}
基になるhibernate/jdbc / db例外をキャッチしようとしています(たとえば、依存エンティティがまだ存在する場合、削除はorg.springframework.orm.hibernate3.HibernateJdbcExceptionで失敗します)、いくつかのアクションを実行します。ただし、キャッチコードに到達することはありません。
しかし、メソッドから「@Transactional(propagation = Propagation.REQUIRED、isolation = Isolation.DEFAULT)」を削除すると、catchブロックに到達します。これはSpringがこれを管理する方法に関係していると思いますが、JDBCException中に例外をキャッチし、@Transactionアノテーションを使用する方法がわかりません。
どんな助けでも大歓迎です!