Java HibernateDaoSupport和本机SQL
我正在用spring和hibernate编写一个DAOJava HibernateDaoSupport和本机SQL,java,hibernate,spring,Java,Hibernate,Spring,我正在用spring和hibernate编写一个DAO public class DaoImpl extends HibernateDaoSupport implements Dao {} 对于读取或更新数据,我使用HQLgetHibernateTemplate().bulkUpdate(…),但其中一个查询太复杂,无法读取或更新数据,我需要使用本机SQLQuery Query=getSession().createSQLQuery(…) 但这样做会挂起我的应用程序 DEBUG org.hib
public class DaoImpl extends HibernateDaoSupport implements Dao {}
对于读取或更新数据,我使用HQLgetHibernateTemplate().bulkUpdate(…)
,但其中一个查询太复杂,无法读取或更新数据,我需要使用本机SQLQuery Query=getSession().createSQLQuery(…)
但这样做会挂起我的应用程序
DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
我可以通过设置DataSource maxActive field unlimited来防止这种情况,但这不是一个解决方案。
我的问题是,有没有可靠的方法将本机SQL与HibernateDataOSupport结合使用?非常重要的是,本机查询需要在与其他(HQL)查询相同的事务中执行
谢谢您可以将HibernateTemplate配置为不创建新会话:
ht.setAllowCreate(false);
ht.setAlwaysUseNewSession(false);
Javadoc:有点离题,但可能会有所帮助。Spring的作者不推荐使用HibernateDaoSupport实现DAO。检查。spring和hibernate?spring 2.5.4和hibernate 3.3.2.GA的版本