我用的是ssh框架,在action中调用hibernate 的findbyId()方法。。调出记录。。修改了一个字段,然后saveOrUpdate,然后又findall调出所以记录列表显示。这就样的操作,连续操作大概有五六次吧应用就无法响应了。。为什么呢。。我该怎么优化一下呢? 是不是在spring中配置些什么呢? 高手请指教!

解决方案 »

  1.   

    是在Spring中配置一点东西<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
               
    <bean id="SessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
    </property>
    </bean>  
    自己看看我也不知道是哪
      

  2.   

    没有出现任何错误提示么? 我很期待谁能回答这个问题 虽然我现在不用Hibernate了 但是我当初用的时候偶尔也会有类似情况
      

  3.   

    这是hibernate自己的问题,一般hibernate与数据库交互8次就会挂了,而且程序也不会报错,就是不运行
      

  4.   

     LZ的控制层用的是Servlet么?
      

  5.   

    建议Lz用c3p0管理一下就不会出现那问题了
      

  6.   

    业务逻辑bean里调用dao,一个业务逻辑方法给一个session就可以了
      

  7.   

    是数据库连接释放的问题,你数据库连接没有释放,
    1\你的数据库访问类如果继承或者扩展HibernateDaoSupport,可利用spring容器的机制去释放
    2\建议你将这些操作放到一个事务下,可以使用容器事务配置的方式来定义,不用改程序.
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="find*" read-only="true" />
    <tx:method name="get*" read-only="true" />
    <tx:method name="check*" read-only="true" />
    <tx:method name="query*" read-only="true" />
    <tx:method name="*" />
    </tx:attributes>
    </tx:advice>
    <aop:config proxy-target-class="true">
    <aop:pointcut id="service"
    expression="execution(* test1.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="service" />
    </aop:config>
      

  8.   

    要不连接没释放,要不有update没提交锁表咯。
      

  9.   

    hibernate本身有个延迟加载(也有叫懒加载的)的属性,把它关了就行了,属性名lazy
    具体的记不得了,
      

  10.   

      问题解决了。。原来是我getSession 的时候忘了释放! 呵呵  
      

  11.   

    我写的是Spring里 的配置,有一句话起作用,但是要是不写的话就肯定费掉,当初做项目的时候就是这样的问题,我们没有你的Session的释放问题
      

  12.   

    换成hibernate3.2试试,我用3.0就老有这种错误。用了3.2就没了