I think i don’t understand something with unchecked exception.
I’m using spring/hibernate.
In a transaction, i’m catching a NullPointerException (so an unchecked), but at then end my transaction is not rollbacked.
Is it because i catch the NPE inside the same method that throw the NPE ?
This is the only diffrent i see from an other part of the code where i throw an IllegalArgumentException that is catched in an other method from the one throwing it ( and which ends with a rollback. )
Thank you,
Spring will rollback the transaction if an uncaught exception goes through the transactional proxy.
If you catch the exception inside the wrapped method, the transaction will not be rolled back automatically.
If you do need to catch the exception for some reason, you could either rethrow it, throw another one (one that makes sense considering the contract of the method) or rollback the transaction manually. Keep in mind that this last option breaks the transparancy of spring.