I have working Hibernate/Spring web-app (HibernateDaoSupport, getHibernateTemplate(), etc). For several tasks i need to use JDBC (jdbcTemplate ?). How to do it in that scenerio ?
I have working Hibernate/Spring web-app ( HibernateDaoSupport , getHibernateTemplate() , etc). For several tasks
Share
Just create
JdbcTemplateand use the sameDataSourcethat is being used byHibernateDaoSupport,HibernateTemplate. Hibernate is just a fancy library working on top of JDBCDataSource/connection. You might use it manually. Try:If you are lucky, this should work. A better idea is to create
JdbcTemplateas a Spring bean and inject proper data source:Consider using
JdbcOperationsinterface, also look at SimpleJdbcOperations.If you start to access the same database/connection pool both by Hibernate and using direct JDBC access code, you have to watch out for some side effects:
Another approach is to access JDBC connection used by Hibernate session (in
HibernateDaoSupport: