spring-transactions

Inconsistent JPA behavior using no transaction, propagation SUPPORTS and OpenEntityManager pattern

不羁岁月 提交于 2019-12-24 11:24:36
问题 We are using JPA (Hibernate 4) with Spring 4 managing the JTA transactions. To allow lazy initialization even when simply reading from the database without any transaction we added the "OpenEntityManager" pattern. You can find a test case for these questions on GitHub https://github.com/abenneke/sandbox/tree/master/spring-hibernate4-transaction We know that there is a difference between having no transaction synchronization at all and SUPPORTS synchronization. But the JPA behaviour seems to

Dynamically changing session factory and Txm Manager for I18N support

≡放荡痞女 提交于 2019-12-24 10:36:58
问题 I have a peculiar issue here in the Spring-GWT application we are building. We have an oracle DB encoded in WE8ISO8859P1 character set which doesn't support UTF-8 . Hence we are building a new DB in AL32UTF8 char set . Unfortunately the DBAs do not want to migrate the existing DB to the new DB and we have to reach the old DB for the English data and the new DB for the Latin data . We have @Transactional annotations at method/class level and the sessionFactory is injected into the DAO to

How to make the queries in a stored procedure aware of the Spring Transaction?

别等时光非礼了梦想. 提交于 2019-12-24 09:59:29
问题 After I execute a bunch of queries on the DB, I'm calling a stored procedure from a Spring Transaction (a Spring Service marked with @Transactional). entityManager.createNativeQuery("call stored_procedure()"); query.executeUpdate(); In order to make the queries of the stored procedure rollback when an exception is thrown by the java code (or the modifications of the DB made in the javacode rolled back because of an exception thrown in the stored procedure), I've set the autocommit variable of

spring transaction timeout configurable

Deadly 提交于 2019-12-24 07:47:43
问题 I have a transactional method which has a fixed timeout. Is there a way to make a transaction timeout configurable through i.e. an application.yml ? @Transactional(propagation = Propagation.REQUIRED, timeout = TIMEOUT) public String doStuff(String id) throws Exception { service.doSomeStuff } 回答1: As we cannot assign variable value to Java annotation attribute , to programmatically set @Transactional 's timeout , your best bet is to override AbstractPlatformTransactionManager#determineTimeout(

Spring Data/Hibernate MS SQL Server unique constraint and race condition

筅森魡賤 提交于 2019-12-24 03:23:42
问题 Some time ago I ran into the race condition issue when 2 separate transactions try to simultaneously check if the record exists(by 4 fields) and if no - create a new one. My environment: MS SQL Server , Spring Data / JPA / Hibernate It was a duplicate records issue. I implemented the test that simulates concurrent calls and thus was able(pretty stable at 99.99% of execution times) to reproduce this issue. Right now I'm fixed this issue by applying unique constraint over these 4 fields. At

Controlling inner transaction settings from outer transaction with Spring 2.5

时间秒杀一切 提交于 2019-12-23 13:19:11
问题 I'm using Spring 2.5 transaction management and I have the following set-up: Bean1 @Transactional(noRollbackFor = { Exception.class }) public void execute() { try { bean2.execute(); } catch (Exception e) { // persist failure in database (so the transaction shouldn't fail) // the exception is not re-thrown } } Bean2 @Transactional public void execute() { // do something which throws a RuntimeException } The failure is never persisted into DB from Bean1 because the whole transaction is rolled

@EnableTransactionManagement,@ComponentScan and DataSourceTransactionManager problems

怎甘沉沦 提交于 2019-12-23 13:07:59
问题 In my application, I am using annotation-based spring configuration. I was using @ComponentScan (and it worked fine). Now I'm trying to add simple transaction management using @EnableTransactionManagement . However, when I add it, I start getting errors with one of the beans not being found (i.e. I get BeanCreationException because of NoSuchBeanDefinitionException ). There is no other error (i.e. there is nothing related to the transaction management). When I comment

Spring @Transactional Timeout not working as expected

馋奶兔 提交于 2019-12-23 12:54:31
问题 I have a JDBC batch update operation which might take long time, hence I am using transaction timeout to handle this. @Override @Transactional(propagation=Propagation.REQUIRES_NEW,timeout=10) public void saveAllUsingBatch(List<KillPrintModel> list){ PreparedStatmentMapper ps= new HibernateDao.PreparedStatmentMapper<KillPrintModel>() { @Override public void prepareStatement(PreparedStatement ps, KillPrintModel t) throws SQLException { ps.setString(1, t.getOffice()); ps.setString(2, t

Multi-threading Spring Transaction

倾然丶 夕夏残阳落幕 提交于 2019-12-23 12:47:38
问题 Assume that we go inside a method and start a transaction in main thread. In this method, there are some async methods so we created 2 more threads inside this method; Thread 1 --> SubMethod1 --> Saving (t=1) ^ | MainThread --> MainMethod --> Saving (t=3) | v Thread 2 --> SubMethod2 --> Exception while saving (t=2). Since thread 2 gets an exception, I want to rollback all transactions done by other threads. However, although transactions owned by main thread an Thread 2 can be roll-backed, I

Spring's TransactionInterceptor overrides my Exception

China☆狼群 提交于 2019-12-23 11:59:19
问题 I have a DAO class catching the javax.persistence.PersistenceException wrapping them and rethrowing it as a checked exception. This method is marked as @org.springframework.transaction.annotation.Transactional . If I get an exception in my DAO like constraint violation it will be wrapped in my custom Exception, however spring overrides my exception [tp1415357209-22] o.s.t.i.TransactionInterceptor : Application exception overridden by commit exception and throws it's own org.springframework