How far does the spring framework go with transaction handling? My reading of the book “Spring In Action” suggestions with its examples that you create DAO methods that don’t worry about Session and Transaction management fairly simply by setting up a session factory and transaction template in XML and then wiring them into your DAO. SpringSource.org’s documentation, on the other hand, suggests that need tons of XML and/or annotation to make this happen.
What is the truth here, what is the simplest way I can take code along the lines of
get session from sessionfactory
open transaction
preform database actions
commit transaction with error handling
and make it just
preform database actions
reducing the amount of boiler plate transactional code that I have across my methods to a minimum?
Spring provides at least 3 ways of transaction demarcation:
1) Programmatic handling, via TransactionTemplate or PlatformTransactionManager – light on config, but invasive
2) Declarative via XML – verbose XML, but non-invasive
3) Declarative via annotations – light on XML, not invasive
Which one you pick depends on which one best suits your needs, Spring doesn’t make that choice for you. From your question, it sounds like the annotation approach is what you’re after.
I suggest reading the Spring reference manual, the section of annotation-driven transaction handling. It’s clear and concise.
I always consult the ref docs first, and only consult a book if it’s not in the docs.