用jquery 写了一个前台分页 ajax 请求,返回 json 类型,
在页面刷新6-7次后卡住了,返回不了数据,开始几次返回数据并没有问题。
程序不报错,排查发现是停在dao层中的query.list()方法动不了,
dao层代码如下
public List<Activity> listAllActivity() { System.out.println("listAllActivity.dao-------------"); Session session = sessionFactory.getCurrentSession(); String hql = "from Activity a order by a.activityid desc"; Query query = session.createQuery(hql); System.out.println("listAllActivity.dao-------------"); System.out.println(query.list()); return query.list(); }
spring配置文件中sessionFactory的代码如下
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <!-- <prop key="hibernate.connection.release_mode">auto</prop> --> </props> </property> <property name="mappingResources"> <list> <value>com/cu/pojo/User.hbm.xml</value> <value>com/cu/pojo/Activity.hbm.xml</value> <value>com/cu/pojo/Order.hbm.xml</value> <value>com/cu/pojo/Route.hbm.xml</value> </list> </property> </bean>
是不是刷新时每次都opensession,导致线程不够,所以卡住不动,那应该怎么改,网上说将opensession改成getCurrentSession,那应该在那里改
解决了 忘记关闭session