0

I am trying to make a transaction fail for all the unchecked exceptions except for a particular unchecked exception(in my case - DuplicateKeyException). How can I achieve this customization using @Transactional annotation of Spring framework ?

Thank you!

Seema
  • 81
  • 8
  • So what do you expect to happen when DuplicateKeyException happen? What's your definition of transaction 'not failing'? – gerrytan Sep 12 '13 at 02:57
  • I catch the DuplicateKeyException exception and continue the transaction. If set @Transactional(propogation=Propogation.NEVER) everything goes as I expect otherwise it gives me the following error message: org.springframework.jdbc.core.StatementCreatorUtils - JDBC 3.0 getParameterType call not supported org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block – Seema Sep 12 '13 at 03:10

2 Answers2

0

Try the noRollbackFor option

@Transactional(noRollbackFor=DuplicateKeyException.class)
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • I tried this, but it gives the same error. The problem seems to be that the transaction is failing and this tell the transaction manager what should be the roll back action on failed transaction – Seema Sep 12 '13 at 16:00
0

Do it like this :

public void driverMethod(){
try{
   BeforeException()
}
catch(DuplicateKeyException e)
   AfterException()
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
private BeforeException(){
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
private AfterException(){
}