@Transactional, how it's working?
In my first Spring application, i'm tried to use transactions. I'm using JdbcTemplate and i'm have 2 tables: messages and pictures.
Method used for adding message, looks like:
1) updating messages table and returning KeyHolder
2) updating pictures table, query based on KeyHolder
I need to rollback transaction if something goes wrong. I using next sequence:
mark method as @Transactional(propagation = Propagation.REQUIRED)
try {
1) updating messages table and returning KeyHolder
throw new Exception();
2) updating pictures table, query based on KeyHolder
} catch
I expect that, Spring will make (1) and exit from try block, without making (2). So, transaction will be rollbacked.
BUT
Spring adds new message, and don't adds new picture. So, i have message without picture, as result.
Please help me to use @Transactional correctly. Tnx!