事物配置

<?xml version="1.0" encoding="UTF-8"?>

<!--
- Application context definition for JPetStore's business layer.
- Contains bean references to the transaction manager and to the DAOs in
- dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
-->
<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.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.gtac.*.service.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>

</beans>
MySQL是一个流行的关系型数据库管理系统,用于存储和管理数据。下面是安装MySQL并在Windows上配置一个基本事物处理环境的步骤: **安装MySQL:** 1. 访问MySQL官方网站(https://www.mysql.com/downloads/)下载适用于您操作系统的最新版本。 2. 运行安装文件,遵循提示进行安装。确保选择"典型安装"或包含客户端工具的安装选项。 3. 安装过程中可能会要求输入root用户的密码,这是管理数据库的主要账户。 **配置MySQL:** 1. 安装完成后,启动MySQL服务(在Windows上通常可以通过服务管理器或命令行运行`services.msc`或`mysqld.exe --install`)。 2. 首次启动时,MySQL可能提示创建root用户的密码,如果忘记,可以通过命令行执行`ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';`。 3. 启动MySQL命令行客户端(如`mysql -u root -p`)并输入密码,然后设置编码和字符集为UTF-8,以防中文乱码:`SET NAMES utf8;` **配置事务处理:** 1. 事务是数据库操作的一组相关操作,要么全部完成,要么全部回滚。在MySQL中,你可以使用`START TRANSACTION`开始一个事务,`COMMIT`来提交事务,或`ROLLBACK`来回滚事务。 2. 示例代码(在MySQL客户端): ``` START TRANSACTION; -- 执行SQL命令,比如 INSERT, UPDATE 或 DELETE INSERT INTO your_table (column) VALUES ('value'); IF (some_condition) THEN COMMIT; -- 成功时提交事务 ELSE ROLLBACK; -- 没满足条件时回滚事务 END IF; ``` 3. **相关问题--:** 1. MySQL中如何启用自动提交(默认行为)? 2. 在哪些情况下需要手动管理事务? 3. 如何查看当前事务状态? 记得根据你的具体需求调整上述步骤,如果你是Linux用户,安装过程和命令会有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值