spring-transactions

How to configure AspectJ with Load Time Weaving without Interface

天大地大妈咪最大 提交于 2019-12-04 07:48:39
问题 On my project, I currently use AspectJ (not just Spring AOP due to some limitation) with the weaving at the Compile Time. In order to speed up the development on Eclipse, I want to do the weaving at the Load Time. I succeed to do that but with one major constraint: using an interface for my service that contained some transactional methods. If I declare the service with its implementation instead of its interface, in the caller class, there is no weaving and so no transaction supported. So if

Spring Transaction Doesn't Rollback

ぃ、小莉子 提交于 2019-12-04 07:32:50
We have a Spring Transaction rollback issues, where rollback doesn't seems to be working. Within my service layer method which is annotated with @Transactional I call three different DAOImpl classes to insert 3 records. The middle insert do a get from a 4th table to populate a description field but this get failed. I expect the first insert to rollback but it doesn't seems to be happening. Few Points: The 'Get' method throws a Runtime Exception We are using org.springframework.jdbc.datasource.DataSourceTransactionManager and MySQL datasource defined in applicationContext.xml . Beans are

Confusion between @Transactional and AOP

本秂侑毒 提交于 2019-12-04 06:00:30
问题 Does @Transactional is replacement for AOP in spring 3. are they same? Can I say @Transactional implements AOP internally ? 回答1: The @Transactionnal annotation is just a simple way to declare that a method is (or all methods of a class are) transactionnal. The Spring Framework will use an AOP proxy to intercept calls to the method and manage transaction. So, we can say that @Transactionnal use AOP internally. More information here 回答2: What you can say is that Spring uses AOP to add a

Isolation level SERIALIZABLE in Spring-JDBC

穿精又带淫゛_ 提交于 2019-12-04 03:56:49
问题 maybe somebody can help me with a transactional issue in Spring (3.1)/ Postgresql (8.4.11) My transactional service is as follows: @Transactional(isolation = Isolation.SERIALIZABLE, readOnly = false) @Override public Foo insertObject(Bar bar) { // these methods are just examples int x = firstDao.getMaxNumberOfAllowedObjects(bar) int y = secondDao.getNumerOfExistingObjects(bar) // comparison if (x - y > 0){ secondDao.insertNewObject(...) } .... } The Spring configuration Webapp contains:

Attempt to update step execution id=1 with wrong version (2), where current version is 1

廉价感情. 提交于 2019-12-04 02:55:28
Im using SpringBatch 2.1.7 release core and Infrastructure jars to read a CSV file and save it to DB. Integrated my code with Spring quartz scheduler to run for every minute, The Batch is working fine with reading and writing but its failing with the error "org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=1 with wrong version (2), where current version is 1" due to Tx conflicts. Please suggest how can i resolve this issue. I had this same exception. org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=0

hibernate session.flush with spring @transactional

让人想犯罪 __ 提交于 2019-12-04 01:25:09
I am using Spring and Hibernate in my application and using Spring Transaction. So I have a service layer with annotation @Transaction on methods and DAO layer having methods for database query. @Transactional(readOnly = false) public void get(){ } The issue is when I want to save an object in the database,then I have to use session.flush() at the end of DAO layer method. Why? I think if I have annotated @Transaction , then Spring should automatically commit the transaction on completion of the service method. DAO layer : public BaseEntity saveEntity(BaseEntity entity) throws Exception { try {

How to execute custom SQL query with spring-managed transactional EntityManager

丶灬走出姿态 提交于 2019-12-04 01:13:20
I have an application built on Spring. I let the Spring do the all @Transactional magic and everything works fine as long as I operate on my entities that are mapped to Java objects. However, when I want to do some custom job on a table that is not mapped to any of my Java entities, I'm stuck. Some time ago, I found a solution to execute a custom query like this: // em is instance of EntityManager em.getTransaction().begin(); Statement st = em.unwrap(Connection.class).createStatement(); ResultSet rs = st.executeQuery("SELECT custom FROM my_data"); em.getTransaction().commit(); When I try this

How to configure mutliple transaction managers with Spring + DBUnit + JUnit

眉间皱痕 提交于 2019-12-03 15:33:15
In a nutshell My command line Java application copies data from one datasource to another without using XA. I have configured two separate datasources and would like a JUnit test that can rollback data on both datasources. I use DBUnit to load data into the "source" database, but I cannot get this to rollback. I can get the "target" datasource to rollback. My Code Given this config... <tx:annotation-driven /> <!-- note the default transactionManager name on this one --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name=

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

Nested @Transactional methods with @Async

余生颓废 提交于 2019-12-03 11:35:44
I'm using Spring with JPA. I have @EnableAsync and @EnableTransactionManagement turned on. In my user registration service method, I have a few other service methods I call that are annotated @Async . These methods do various things like sending a welcome email and registering the newly minted user with our third party payment system. Everything works well until I want to verify that the third party payment system successfully created the user. At that point, the @Async method attempts to create a UserAccount (that references the newly minted User ) and errors out with a javax.persistence