I want to Remove begin and commit transactions from DAO class , and I need to use Transactional annotation. How it should be done? Now , exception is org.hibernate.HibernateE
There are 2 flaws in your configuration.
First when using @Transactional
you also have to make this clear to your configuration by including a
tag in your application context file. If not your @Transactional
is going to do nothing.
Simple add and add this to your Second you have configured the Another thing to consider is that the actual transactional boundary should be your service layer and not your data access layer. Your service method is an all or nothing operation, if you have 3 database calls they should all participate in the same transaction. With your setup you will get 3 individual transactions, which can leave your database in an undesired state when doing multiple updates for instance. I suggest to move the schemaLocation
attribute.http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
hibernate.current_session_context_class
property in your hibernate configuration. This breaks proper integration with spring which sets it to a custom Spring class, however your setting overrides this. Remove this property.@Transactional
to your service layer instead of the data access layer.