最近要改造一下项目,报出 No Session found for current thread
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/25 17:54:26
最近要改造一下项目,报出 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
最近要改造一下项目,自动扫描注册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
看看你的hibernate配置文件是否配置了:
thread属性,如果配置了,请去掉!
thread属性,如果配置了,请去掉!
最近要改造一下项目,报出 No Session found for current thread
SSH javaweb测试 错误No Session found for current thread
Spring current session是什么
NO SESSION
Session与HttpContext.Current.Session到底有什么区别
在ARCGIS里CURRENT SESSION是什么意思
reading session for reading
No user found for those credentials
No results were found for your search.
Sorry,no search results found for
The name 'Session' does not exist in the current context .
get ready for your session