您的位置:首页 > 编程语言 > Java开发

spring 与 hibernate 及事务的配置

2008-10-29 12:55 393 查看
spring 与hibernate 及事务的配置:
<?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:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- Hibernate SessionFactory -->
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="mysqldataSource1" />
</property>
<!--
<property name="mappingResources">
<list>
<value>com/xh/hibernate/entity/User.hbm.xml</value>
</list>
</property
-->
<property name="mappingLocations">
<list>
<!--value>classpath:/com/company/club/**/*.hbm.xml</value-->
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="hibernateSessionFactory" />
</property>
</bean>

<bean id="abstractTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<!-- prop key="set*">PROPAGATION_REQUIRED,timeout_80</prop-->
<prop key="save*">PROPAGATION_REQUIRED,timeout_80</prop>
<prop key="create*">PROPAGATION_REQUIRED,timeout_80</prop>
<prop key="update*">PROPAGATION_REQUIRED,timeout_80</prop>
<prop key="delete*">PROPAGATION_REQUIRED,timeout_80</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<!--
把事务配置在service层
<bean id="daoTarget" class="a dao class impl " lazy-init="true">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="daoService" parent="abstractTransactionProxy">
<property name="target" ref="daoTarget"/>
</bean>
-->

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: