日期:2014-05-19  浏览次数:20710 次

SSH2 事务代理问题
Java code

 <!-- 配置sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!--        <bean id="sessionFactory" class="org.springframework.orm.toplink.LocalSessionFactoryBean"> -->
        <property name="dataSource" ref="dataSource" />
        
        <property name="mappingResources">
            <list>
                <value>com/onionportal/orm/SystemLog.hbm.xml</value>
            </list>
        </property>
        
        
        <property name="hibernateProperties">
            <props>
                <!--这里设置getcurrentSession的作用域-->
<!--                <prop key="hibernate.current_session_context_class">thread</prop>-->
                <!--设置连接对象-->
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <!--输出sql-->
                <prop key="hibernate.show_sql">true</prop>
                <!--格式化SQL-->
                <prop key="hibernate.format_sql">true</prop>
                <!-- 开启二级缓存-->
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <!-- 是否缓存查询结果 -->
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <!-- 设置缓存类-->
                <prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</prop>
                <!-- 设置memcache缓存服务器端口 -->
                <prop key="hibernate.memcached.servers">192.168.1.110:11211</prop>
                <!-- 设置二级缓存的前缀名称 -->
                <prop key="hibernate.cache.region_prefix">quality.cache.onionPortalCache</prop>
                <!-- 否使用结构化的方式缓存对象  -->
                <prop key="hibernate.cache.use_structured_entries">true</prop>
            </props>
        </property>

    </bean>
    
    
    
       <!--定义Hibernate的事务管理器HibernateTransactionManager -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <!-- 依赖注入上面定义的sessionFactory -->
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <!--定义Spring的事务拦截器TransactionInterceptor -->
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <!--  依赖注入上面定义的事务管理器transactionManager -->
        <property name="transactionManager" ref="transactionManager"/>
          <!-- 定义需要进行事务拦截的方法及所采用的事务控制类型 -->        
        <property name="transactionAttributes">            
            <props>
                <!-- 以browse、list、load、get及is开头的所有方法采用只读型事务控制类型 -->
                <prop key="browse*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
                <!-- 所有方法均进行事务控制,如果当前没有事务,则新建一个事务 -->
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props