springmvc multi-transaction commit and rollback
# mysql = =jdbc:mysql://192.168.:3306/kintech_bo =root =root =3 =3 =200 =20 =60 =1 =1 =200 =20 =60 # sqlserver = = jdbc:sqlserver://192.168.:1433;DatabaseName=logisoft;useSSL=false = sa = sasa #hibernate config = hibernate.show_sql=false hibernate.format_sql=true #hibernate. =update hibernate.=none .use_second_level_cache=false .use_query_cache=false .provider_class= .factory_class=
Configuration
Key point: <!-- Configuring ChainedTransactionManager -->
Starting from Spring Framework version 5.3, Spring provides a new transaction manager implementation class CompositeTransactionManager
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="/schema/beans" xmlns:xsi="http:///2001/XMLSchema-instance" xmlns:context="/schema/context" xmlns:mvc="/schema/mvc" xmlns:aop="/schema/aop" xmlns:tx="/schema/tx" xmlns:p="/schema/p" xmlns:jpa="/schema/data/jpa" xsi:schemaLocation="/schema/beans /schema/beans/spring-beans-4. /schema/context /schema/context/spring-context-4. /schema/mvc /schema/mvc/spring-mvc-4. /schema/aop /schema/aop/spring-aop-4. /schema/tx /schema/tx/spring-tx-4. /schema/data/jpa /schema/data/jpa/" default-lazy-init="true"> <!--mysql Configure data source--> <bean class=".v2." destroy-method="close"> <property name="driverClass" value="${}"/> <!--Database connection driver--> <property name="jdbcUrl" value="${}"/> <!--Database address--> <property name="user" value="${}"/> <!--username--> <property name="password" value="${}"/> <!--password--> <property name="maxPoolSize" value="${}"/> <!--Maximum number of connections--> <property name="minPoolSize" value="${}"/> <!--Minimum number of connections--> <property name="initialPoolSize" value="${}"/> <!--Initialize the database connection in the connection pool--> <property name="maxIdleTime" value="${}"/> <!--Maximum free time--> <property name="idleConnectionTestPeriod" value="${}"/> <!--Check the number of spare connections--> </bean> <!-- hibernate --> <!--Configurationsessionfactory--> <bean class="."> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan" value=""/> <property name="hibernateProperties"> <props> <prop key="hibernate.">${hibernate.}</prop> <!--hibernateAutomatically generate database tables based on entities--> <prop key="">${}</prop> <!--Specify database dialect--> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <!--Display the executed database operation statement on the console--> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <!--Display the executed data cry operation statement on the console(Format)--> <prop key=".use_second_level_cache">${.use_second_level_cache}</prop> <prop key=".use_query_cache">${.use_query_cache}</prop> <!-- Query cache --> <prop key=".provider_class">${.provider_class}</prop> <prop key=".factory_class">${.factory_class}</prop> <prop key="hibernate.allow_update_outside_transaction">true</prop> </props> </property> </bean> <!-- JPA实体管理器factory --> <bean name="jpaEntityManagerFactory" class=""> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/> <!-- Add custom package path --> <property name="packagesToScan" value=".**"> </property> <property name="jpaProperties"> <props> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.">none</prop><!-- validate/update/create --> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <!-- Naming rules for building tables --> <prop key=".naming_strategy"></prop> <!-- Active release mode --> <prop key=".release_mode">after_statement</prop> </props> </property> </bean> <!-- set upJPAImplement the specific properties of the manufacturer --> <bean class=""> <property name="databasePlatform" value="${}"/> </bean> <!-- JPA sqlserver --> <bean class=".v2." destroy-method="close"> <property name="driverClass" value="${}"/> <!--Database connection driver--> <property name="jdbcUrl" value="${}"/> <!--Database address--> <property name="user" value="${}"/> <!--username--> <property name="password" value="${}"/> <!--password--> <property name="maxPoolSize" value="${}"/> <!--Maximum number of connections--> <property name="minPoolSize" value="${}"/> <!--Minimum number of connections--> <property name="initialPoolSize" value="${}"/> <!--Initialize the database connection in the connection pool--> <property name="maxIdleTime" value="${}"/> <!--Maximum free time--> <property name="idleConnectionTestPeriod" value="${}"/> <!--Check the number of spare connections--> </bean> <!-- Integrationsqlserverjpa --> <bean name="sqlserverEntityManagerFactory" class=""> <property name="dataSource" ref="sqlserverDataSource"></property> <property name="packagesToScan" value=".**"> </property> <property name="persistenceUnitName" value="sqlserverdb"></property> <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter2"/> <property name="jpaProperties"> <props> <!--set up外连接抓取树的最大深度 --> <prop key="hibernate.max_fetch_depth">3</prop> <prop key=".fetch_size">18</prop> <prop key=".batch_size">10</prop> <!-- Whether to displaySQL --> <prop key="hibernate.show_sql">false</prop> <!-- showSQL是否Format化 --> <prop key="hibernate.format_sql">false</prop> <!-- Turn off Level 2 cache --> <prop key=".provider_class"></prop> <!-- Turn off Entity Field Mapping Verification --> <prop key="">none</prop> <!-- Active release mode --> <prop key=".release_mode">after_statement</prop> </props> </property> </bean> <!-- set upJPAImplement the specific properties of the manufacturer --> <bean class=""> <property name="databasePlatform" value=""/> </bean> <!-- ConfigurationChainedTransactionManager --> <bean class=""> <constructor-arg> <list> <bean class=""> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <bean class=""> <property name="entityManagerFactory" ref="sqlserverEntityManagerFactory"/> </bean> </list> </constructor-arg> </bean> <!-- mysql jpa --> <jpa:repositories base-package=".*" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/> <!-- sqlserver jpa --> <jpa:repositories base-package="" transaction-manager-ref="transactionManager" entity-manager-factory-ref="sqlserverEntityManagerFactory"/> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> <!-- JPA sqlserver --> </beans>
3. Add @Transactional
Remember to add @Transactional to all related methods
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.