ssh整合时怎么能拿到session来执行HQL语句?
spring+struts2+hbeinate时我写了:basedao代码如下publicclassBaseDaoextendsHibernateDaoSupport{p...
spring+struts2+hbeinate时 我写了:
basedao代码如下
public class BaseDao extends HibernateDaoSupport{
public Session getSess(){
Session session=this.getHibernateTemplate().getSessionFactory().openSession();
return session;
}
不管点出来的是什么getCurrentSession() 都返回了session。
hibernate.cfg.xml配置
<property name="current_session_context_class">thread</property>
applicationContext.xml配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="baseDao" class="com.qygl.dao.BaseDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
请问高手到底怎么能获取到session 。帮我写全些!环境里无异常,提交了有异常,一看12行就是获取session为空,这行Session session=this.getHibernateTemplate().getSessionFactory().openSession();
异常如下:500
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.qygl.dao.BaseDao.getSess(BaseDao.java:11)
com.qygl.dao.BaseDao.findAAA(BaseDao.java:30)
com.qygl.dao.impl.UsersDAO.findName(UsersDAO.java:39)
com.qygl.biz.impl.UsersBiz.login(UsersBiz.java:23)
action.LoginAction.execute(LoginAction.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source) 展开
basedao代码如下
public class BaseDao extends HibernateDaoSupport{
public Session getSess(){
Session session=this.getHibernateTemplate().getSessionFactory().openSession();
return session;
}
不管点出来的是什么getCurrentSession() 都返回了session。
hibernate.cfg.xml配置
<property name="current_session_context_class">thread</property>
applicationContext.xml配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="baseDao" class="com.qygl.dao.BaseDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
请问高手到底怎么能获取到session 。帮我写全些!环境里无异常,提交了有异常,一看12行就是获取session为空,这行Session session=this.getHibernateTemplate().getSessionFactory().openSession();
异常如下:500
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.qygl.dao.BaseDao.getSess(BaseDao.java:11)
com.qygl.dao.BaseDao.findAAA(BaseDao.java:30)
com.qygl.dao.impl.UsersDAO.findName(UsersDAO.java:39)
com.qygl.biz.impl.UsersBiz.login(UsersBiz.java:23)
action.LoginAction.execute(LoginAction.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询