Reputation: 1901
IN spring docs it's written
The most important concepts to grasp with regard to the Spring Framework's declarative transaction support are that this support is enabled via AOP proxies, and that the transactional advice is driven by metadata (currently XML- or annotation-based).
So If i use
<tx:annotation-driven proxy-target-class="true" order="100"/>
in config file and not use @Transactional
annotation on my beans. Would transaction still be supported, as I am using AOP and transaction Interceptor should be built-in to my AOPs thus no use of explicitly using @Transactional
annotation.
Thanks,
Upvotes: 0
Views: 248
Reputation: 9697
< tx:annotation-driven /> is used to auto detect the '@Transactional' annotation .So it's necessary to have one . Reference here.
The proxy-target-class="true" decides whether Spring should use JDK dynamic proxies or CGLIB class based proxies . See the reference for more info . Basically if your class implements atleast one interface, JDK dynamic proxies are used . If you have a class MyDaoImpl extends MyDao and in your service , you inject the dao reference via MyDaoImpl myDaoImpl , JDK dynamic proxies will not work if the annotations are on your interface as class bases proxies are created with proxy-target-class="true" and @Transactional annotation is not inherited .
The reason why your queries seem to work without @Transactional may be because you are using hibernate template which opens and closes the transactions internally . From Spring 3 , it is recommended to inject sessionFactory directly and not to use hibernate template .
Hope this helps.
Upvotes: 1
Reputation: 62573
No, you'd still have to use the @Transactional
annotation. AOP proxy is only used to inject the transaction related code into your code.
Upvotes: 3