I am working on a project which uses Spring 3.0, hibernate 3.0. My project has Controller, Service and DAO layers. Daos(written in hibernate) are accessed from service layer
I am writing this answer in hope that people will improve mine answer as this may not be the best answer so please comment.
In hibernate you can use named native query example : http://www.java2s.com/Code/Java/JPA/UsingNamedNativeQuery.htm Scroll a little bit down and find File: Professor.java You can use this example. This way you can fire native queries from hibernate.
You can safely mix hibernate with spring JDBC and both should be able to share transactions managed by HibernateTransactionManager
. Keep in mind you should be using spring templates to achieve this because they are able to detect and reuse thread-bound connection with active transaction. If for some reason you would like to add another jdbc based library to the mix (like groovy sql for example) you can still do it through spring DataSourceUtils
.
The only potential issues can arise when both hibernate and spring jdbc templates operate on the same data. Hibernate may delay database updates and spring jdbc would then access outdated data. My experience with this interaction comes from older versions of spring and there may be some mechanisms to resolve this issue nowadays.