views:

379

answers:

2

Hi

I'm writing a DAO using spring and hibernate

public class DaoImpl extends HibernateDaoSupport implements Dao {}

For reading or updating data I'm using HQL getHibernateTemplate().bulkUpdate(...) but one of the queries is too complex for that and I need to use native SQL Query query = getSession().createSQLQuery(...)

But doing that hangs my application

DEBUG org.hibernate.jdbc.ConnectionManager  - opening JDBC connection

I can prevent this by setting DataSource maxActive field unlimited, but that's not a solution. My question is that is there any solid way of using native SQL with HibernateDaoSupport? Very important is that native queries needs to be executed in same transaction as other (HQL) queries.

Thanks

+1  A: 

You can configure HibernateTemplate not to create new session:

ht.setAllowCreate(false);
ht.setAlwaysUseNewSession(false);

Javadoc: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/HibernateTemplate.html#getSession%28%29

splix
A: 

Slightly off-topic but possibly helpful nonetheless. Using HibernateDaoSupport to implement your DAO's is not recommended by the authors of Spring. Check this blog posting.

Hans Westerbeek