最近要改造一下项目,报出 No Session found for current thread最近要改造一下项目,自动扫描注册service和dao,自动注入dao、service;但遇到No Session found for current thread 的问题,配置如下:public class Hibernate

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 14:48:52
最近要改造一下项目,报出 No Session found for current thread最近要改造一下项目,自动扫描注册service和dao,自动注入dao、service;但遇到No Session found for current thread 的问题,配置如下:public class Hibernate
xUkoA~+ Yj_bgbeXFP0 j_XXJ4)J ?݁_p6&d؝sܙ)#$dq׈ebL+w+k[nГ{̘̌UĄ#b(B@ #B&?5ncYeK=,jU%!"uH0/?{`R4g7.b= 1127eA e4 [_uwb4(7m0TSs3"N$܃Peے(; $RHZZ';U2ׯ A?}8hE+KOi{2菓n;XfCG\:! :/QQ4woV LKz:\b!D<[diG4ncqZ(hŽ¶:$z'.0SGS%!x("βr/KLb vMpC.[CF'{r#:^>_")j_ZG}k3ʊ$cQQ-[r pj@m`7{]q Қs8snոS$qS0Ճ\J1mwƺww2 e@bvdyghi{ kíIjZ9E+#@h<ށ~GJf,Mn5st9ku6ݴYϴbt3= 'Խ]=1b

最近要改造一下项目,报出 No Session found for current thread最近要改造一下项目,自动扫描注册service和dao,自动注入dao、service;但遇到No Session found for current thread 的问题,配置如下:public class Hibernate
最近要改造一下项目,报出 No Session found for current thread
最近要改造一下项目,自动扫描注册service和dao,自动注入dao、service;但遇到No Session found for current thread 的问题,配置如下:

public class HibernateDAO {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected SessionFactory sessionFactory;
protected Class entityClass;
public HibernateDAO() {
this.entityClass = ReflectionUtils.getSuperClassGenricType(getClass());
}
public HibernateDAO(final SessionFactory sessionFactory,
final Class entityClass) {
this.sessionFactory = sessionFactory;
this.entityClass = entityClass;
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(final SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession() {
return sessionFactory.getCurrentSession();
}
}
在setSessionFactory 上加 @Autowired 的时候,报出错误为:
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:881)
去掉的话报错为:
java.lang.NullPointerException
at com.base.HibernateDAO.getSession(HibernateDAO.java:110)
at com.base.HibernateDAO.createCriteria(HibernateDAO.java:359)
有木有大侠知道,这是什么问题啊?请指导一下啊:
更详细的说明在这(加了spring配置文件):https://gist.github.com/1722866

最近要改造一下项目,报出 No Session found for current thread最近要改造一下项目,自动扫描注册service和dao,自动注入dao、service;但遇到No Session found for current thread 的问题,配置如下:public class Hibernate
看看你的hibernate配置文件是否配置了:
thread属性,如果配置了,请去掉!