I have just started making a project using spring and hibernate. My DAO layer class extends HibernateDaoSupport. We are not using annotations.
Earlier, we were using struts, hence we used getTransaction, commit, rollback .. methods provided by Session class.
My requirement is very simple, for all DAO classes, if there is an exception, rollback otherwise commit. Please suggest a simplest way of introducing spring transaction management.
I have just started making a project using spring and hibernate. My DAO layer
Share
A few things are not clear from your question. My explanation follows based on below assumptions –
Here is what your spring configuration would look like.
Once this is set up, you could use spring transactional annotations on your DAO methods as shown below. Spring would take care of starting transactions, committing your transactions or rolling back your transactions when exceptions are thrown. If you have business services, you would ideally use transactional annotations on your services instead of DAOs.
Below code shows how transaction management could be achieve using spring’s support for AOP rather than annotations.
For additional details, please see –
Spring Declarative Transactions