transactionmanager

Spring Boot with 2 database configs - lazy loading with second config does not work

被刻印的时光 ゝ 提交于 2019-12-08 07:59:33
问题 I have Spring Boot project with 2 database configs. Primary DB config: @Configuration @EnableTransactionManagement @EnableJpaRepositories(transactionManagerRef = "primaryTransactionManager", entityManagerFactoryRef = "primaryEntityManagerFactory", basePackages = { "com.example.repository.primary" }) public class PrimaryDbConfig { @Primary @Bean(name = "primaryDataSource") @ConfigurationProperties(prefix = "spring.primary.datasource") public DataSource dataSource() { return DataSourceBuilder

Why are the transactions rolled back even when propagation=Propagation.REQUIRES_NEW in second method in Spring service class?

吃可爱长大的小学妹 提交于 2019-12-06 02:26:07
问题 Basic settings are all fine now and I started to try transactions. Struts+Spring+Hibernate annotation transaction manager. This is the sample code in Action, will call a service class: userService.addUser(); Here is the addUser() method in service class: @Transactional(value="deu" ) public void addUser() { userDao.addUser(); this.addUser2(); } First, I called addUser in userDao, which will insert a user. Second, I called addUser2 in another method in this service class. @Transactional(value=

Spring JDBC transaction manager

社会主义新天地 提交于 2019-12-05 02:26:02
问题 I try to write a transaction manager using JDBC in Spring. my app-servlet.xml <!-- JDBC Config --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <!-- dataSource TransactionManager --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"

Spring JDBC transaction manager

☆樱花仙子☆ 提交于 2019-12-03 17:10:56
I try to write a transaction manager using JDBC in Spring. my app-servlet.xml <!-- JDBC Config --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <!-- dataSource TransactionManager --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="UserDAOImpl" class="com.project.dao.impl.UserDAOImpl"> <property

Does the Spring transaction manager bind a connection to a thread?

我怕爱的太早我们不能终老 提交于 2019-12-03 12:35:30
I found the following thread: How exactly JdbcTemplate with TransactionManager works together? The first sentence of that: As far as I understood DataSourceTransactionManager binds a JDBC connection from the specified DataSource to the current thread, allowing for one thread-bound Connection per DataSource. If it's a pool of connections, it will take one of the available connections. ... is exactly what I want to know. When using a transaction manager, do you end up with each thread having it's own single connection? Also, how long does that connection live? Does the same thread use the same

How do you test Spring @Transactional without just hitting hibernate level 1 cache or doing manual session flush?

雨燕双飞 提交于 2019-11-30 15:17:09
问题 Using Spring + Hibernate and transactional annotations. I'm trying to test the following: call a method that changes a User object then calls a @Transactional service method to persist it read the object back from the DB and insure it's values are correct after the method The first problem I had was reading the User object in step 2 just returned the one in the Hibernate level 1 cache and did not actually read from the database. I therefore manually evicted the object from the cache using the

How do you test Spring @Transactional without just hitting hibernate level 1 cache or doing manual session flush?

匆匆过客 提交于 2019-11-30 14:00:53
Using Spring + Hibernate and transactional annotations. I'm trying to test the following: call a method that changes a User object then calls a @Transactional service method to persist it read the object back from the DB and insure it's values are correct after the method The first problem I had was reading the User object in step 2 just returned the one in the Hibernate level 1 cache and did not actually read from the database. I therefore manually evicted the object from the cache using the Session to force a read from the database. However, when I do this, the object values are never

Spring @Transactional with a transaction across multiple data sources

冷暖自知 提交于 2019-11-29 10:43:25
问题 I have to update two data sources as part of one transaction. That is - I do an update in DB1. Then, I do another update in DB2. If update in DB2 fails, I want to roll back both DB1 and DB2 to roll back. Can this be accomplished using @Transactional ? Here is a sample code - @Transactional(value="db01TransactionManager") public void updateDb01() { Entity01 entity01 = repository01.findOne(1234); entity01.setName("Name"); repository01.save(entity01); //Calling method to update DB02 updateDb02()

What is a good open source Java SE JTA TransactionManager implementation? [closed]

淺唱寂寞╮ 提交于 2019-11-28 18:43:53
Basically, what it says on the tin; I need a JTA implementation useable in a Java SE application, ideally one that doesn't carry too much of a framework burden with it. erickson I recommend Bitronix . Before using any other transaction manager, I recommend thorough testing. Tests like killing power to various machines during each phase of the transaction. You want transactionality to protect you when failures occur. It is surprising how many transaction managers have failed to correctly implement recovery. Bitronix does need JNDI, which is typically provided for you in a Java EE container, but

分布式事务系列(2.1)分布式事务的概念

时光怂恿深爱的人放手 提交于 2019-11-28 11:04:10
#1 系列目录 分布式事务系列(开篇)提出疑问和研究过程 分布式事务系列(1.1)Spring事务管理器PlatformTransactionManager源码分析 分布式事务系列(1.2)Spring事务体系 分布式事务系列(2.1)分布式事务模型与接口定义 分布式事务系列(3.1)jotm的分布式案例 分布式事务系列(3.2)jotm分布式事务源码分析 分布式事务系列(4.1)Atomikos的分布式案例 #2 X/Open DTP DTP全称是Distributed Transaction Process,即分布式事务模型。之前我们接触的事务都是针对单个数据库的操作,如果涉及多个数据库的操作,还想保证原子性,这就需要使用分布式事务了。而X/Open DTP就是一种分布式事务处理模型。 ##2.1 X/Open DTP模型 X/Open是一个组织,维基百科上这样说明: X/Open是1984年由多个公司联合创建的一个用于定义和推进信息技术领域开放标准的公司 上述组织就针对分布式事务提出了一个模型,即DTP模型(Distributed Transaction Process),该模型如下所示: 上面主要涉及了三个对象: AP(Application Program):应用程序 TM(Transaction Manager):事务管理器 负责协调和管理事务