spring3.1+hibernate4.1关于事务的配置

来源:互联网 发布:stm8编程手册中文版 编辑:程序博客网 时间:2024/05/16 09:52

spring3.1+hibernate4.1关于事务的配置 --》搞了很久 不过hibernate的更新过快!!!!spring是不是跟不上啊

标签:Hibernate Spring

[1].[代码] spring3.1+hibernate4.1关于事务的配置 跳至 [1]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
---注意hibernate4的版本头信息与hibernate3的不同 可能会报错  具体的可以到hibernate核心包下copy
 
<?xml version="1.0"encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    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-3.1.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    ">
   <bean id="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
         <property name="driverClass"value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
         </property>
         <property name="jdbcUrl"value="jdbc:sqlserver://localhost:1433;databaseName=FundDb">
         </property>
         <property name="user"value="sa"></property>
         <property name="password"value="123456"></property>
    </bean>
     
    <bean id="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
          <property name="dataSource"ref="dataSource"></property> 
         <property name="hibernateProperties"
         <props> 
                <prop key="hibernate.dialect"
                    org.hibernate.dialect.SQLServerDialect
               </prop> 
               <prop key="hibernate.show_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.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                </props> 
       </property> 
        <property name="mappingResources"
           <list> 
                 <value>com/entity/Admin.hbm.xml</value> 
           </list> 
         </property> 
    </bean> 
    <bean id="tran"class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
      
     <tx:advice id="aa"transaction-manager="tran">
            <tx:attributes>
                   <tx:method name="add*"propagation="REQUIRED" isolation="READ_COMMITTED"  />
                   <tx:method name="*"read-only="true"propagation="REQUIRED"/>
            </tx:attributes>
     </tx:advice>
      
     <aop:config proxy-target-class="true">
           <aop:pointcut expression="execution(* com.dao.*.addoneadmin(..))" id="my"/>
           <aop:advisor advice-ref="aa" pointcut-ref="my"/>
     </aop:config>
        
    <bean id="admindao"class="com.dao.AdminDao"p:sf-ref="sessionFactory"></bean>
      
    </beans>

 

0 0
原创粉丝点击