日期:2014-05-18  浏览次数:20690 次

getCurrentSession方法为什么报错了!!
在整理springMVC+hibernate。
配置好了,在dao中使用注入:
@Resource
private SessionFactory sessionFactory;


protected Session getSession() {
System.out.println(sessionFactory);
return sessionFactory.getCurrentSession();
}

这里的return报错了:
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/classic/Session;

之前用的ssh中没问题啊,是不是因为我包换了原来ssh的是hibernate3的 现在换成了4的。
如果4不支持的话,我想在dao中使用hql语句。怎么处理啊!!!

------解决方案--------------------
hibernate配置文件sessionfactory添加
 <property name= "hibernate.current_session_context_class">thread</property>
试试
------解决方案--------------------
引用:
Quote: 引用:

hibernate配置文件sessionfactory添加
 <property name= "hibernate.current_session_context_class">thread</property>
试试


<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name= "hibernate.current_session_context_class" value="thread" />
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.jd.oa.entity.User</value>
</list>
</property>
</bean>

报错了,说没有这个配置项!!

换成hibernate3试试 hibernate4估计设计不同了也可能
------解决方案--------------------
引用:
Quote: 引用:

hibernate配置文件sessionfactory添加
 <property name= "hibernate.current_session_context_class">thread</property>
试试


<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name= "hibernate.current_session_context_class" value="thread" />
<property name="dataSource"&nb