zoukankan      html  css  js  c++  java
  • SSH总结

    1. Spring3.X 与 Hibernate4.X

     http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    ...
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
         <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    1、spring3.x 去掉了对 Hibernate 4.x的 HibernateDaoSupport类。Dao层需要Spring注入SessionFactory对象,通过SessionFactory.getCurrentSession()方法或SessionFactory.openSession()来获得Session对象。

    通过getCurrentSession()方法获取Session对象时需要设置:

    <prop key="hibernate.current_session_context_class">

    org.springframework.orm.hibernate4.SpringSessionContext

    </prop> 

     

    2、缓存设置改为

    <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop> 

    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>

     

    3、spring 3.x对 hibernate 4.x的事务管理,不论是注解方式还是配置文件方式统一改为:

    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" >

    <property name="sessionFactory" ref ="sessionFactory"/>

    </bean>

    sessionFactory 要通过 dataSource 的方式配置,否则出现下面错误:

    Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]

     

    4getCurrentSession()事务会自动关闭,所以在有所jsp页面查询数据都会关闭session。要想在jsp查询数据库需要加入org.springframework.orm.hibernate4.support.OpenSessionInViewFilter过滤器。

     

    5hibernate分页出现 ResultSet may only be accessed in a forward direction需要设置hibernate结果集滚动 <prop key="jdbc.use_scrollable_resultset">false</prop>

     

    6、当报No Session found for current thread异常时

    When openSessionInView filter is not active, getCurrentSession() should be called inside an existing transaction.

    So, to ensure creation of transaction you need to make your service method @Transactional as well (or change propagation of your DAO method to REQUIRED).

  • 相关阅读:
    Function overloading and return type
    Function overloading and const keyword
    Function Overloading in C++
    web安全测试相关内容(三)
    web安全测试相关内容(二)
    web安全测试相关内容(一)
    CDNDrive 第一个版本发布 & 布客新知第二次备份完成
    PyTorch 1.4 中文文档校对活动正式启动 | ApacheCN
    布客&#183;ApacheCN 编程/大数据/数据科学/人工智能学习资源 2020.2
    计算机电子书 2019 BiliDrive 备份
  • 原文地址:https://www.cnblogs.com/ifzhuanzhu/p/2687233.html
Copyright © 2011-2022 走看看