spring-transactions

Spring application has Cglib2AopProxy warnings

烈酒焚心 提交于 2019-12-18 11:25:42
问题 Upon starting my application, I get numerous warnings along the lines of o.s.aop.framework.Cglib2AopProxy 'Unable to proxy method [public final void org.springframework.jdbc.core.support.JdbcDaoSupport.setDataSource(javax.sql.DataSource)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.' for about a dozen or so functions. Now I perfectly understand that proxy-based aspects cannot be applied to final methods. However, I did not (on purpose, at

Spring @Transactional is not working

十年热恋 提交于 2019-12-18 08:48:22
问题 I am trying to use annotated TX Spring support. Application context XML: <?xml ...> <tx:annotation-driven/> <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"> ... </bean> <bean id="repository" class="Repository"> <constructor-arg ref="dataSource"/> </bean> </beans> Actual code: public class Repository { @Transactional public void save(Op op) { System.out.println("Transaction active:::: " + TransactionSynchronizationManager.isActualTransactionActive()); ... } } Calling code:

Using Custom AnnotationTransactionAttributeSource with tx:annotation-driven

我与影子孤独终老i 提交于 2019-12-18 07:06:33
问题 I need to use a Custom AnnotationTransactionAttributeSource in order to intercept transaction attributes. Right now, I do this using the TransactionInterceptor and injecting this in TransactionAttributeSourceAdvisor .The proxies are created using DefaultAdvisorAutoProxyCreator as given below. <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name=

Hibernate collection is not associated with any session

岁酱吖の 提交于 2019-12-18 03:08:09
问题 I have found several questions and answers with regard to this issue on SO, but they all seem to cover one major cause of the problem: fetching a collection outside of a transaction or within another transaction. But in my case, I am fetching within the same transaction when fetching a parent object and collection. @Service @Transactional public class IntegrationServiceImpl implements IntegrationService { @Override public Integration getIntegrationByIdFetchBackendParameters(Long integrationId

Write operations are not allowed in read-only mode - Issue while persisting

时间秒杀一切 提交于 2019-12-17 21:12:26
问题 I have been facing the below error while trying to save the object to database. I tried the solution mentioned here1 and here2 but no good. I was following a tutorial but the only difference is versions of Spring and Hibernate. I am able to persist the object directly using the SessionFactory but it fails with below error if I try this with HibernateDaoSupport spring.xml <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc

Spring @Transactional method - participating transaction

依然范特西╮ 提交于 2019-12-17 19:46:21
问题 in one dao I have 2 @Transactional methods. if i do not provide any explicit properties, then what will happen, if I run one method in the body of another? Both methods will run within THE SAME ONE TRANSACTION? 回答1: Proxies in Spring AOP When using Transactional, you're dealing with proxies of classes, so in this scenario: @Transactional public void doSomeThing(){ // calling this method targets a proxy doSomeThingElse(); // this method targets the actual class, not the PROXY, // so the

Handle spring-data-rest application events within the transaction

帅比萌擦擦* 提交于 2019-12-17 18:43:30
问题 I need to publish notification events to external systems over JMS, when data is updated. Id like this to be done within the same transaction as the objects are committed to the database to ensure integrity. The ApplicationLifecycle events that spring-data-rest emits seemed like the logical place to implement this logic. @org.springframework.transaction.annotation.Transactional public class TestEventListener extends AbstractRepositoryEventListener<Object> { private static final Logger LOG =

How to manually force a commit in a @Transactional method? [duplicate]

懵懂的女人 提交于 2019-12-17 08:31:06
问题 This question already has answers here : How to flush data into db inside active spring transaction? (4 answers) Closed 4 years ago . I'm using Spring / Spring-data-JPA and find myself needing to manually force a commit in a unit test. My use case is that I am doing a multi-threaded test in which I have to use data that is persisted before the threads are spawned. Unfortunately, given that the test is running in a @Transactional transaction, even a flush does not make it accessible to the

Spring + Hibernate manually creating transactions, PROPAGATION_REQUIRED fails. BUG?

你说的曾经没有我的故事 提交于 2019-12-13 23:26:40
问题 PLEASE DO NOT RECOMMEND THAT I USE TRANSACTION ANNOTAIONS FOR THIS. I have run into what appears to be a bug, related to Spring handling of transactions. Please have a look at these two test cases, comments are in the code: Entity class for example: @Entity public class Person{ @Id String name; } Some methods used: public TransactionStatus requireTransaction() { TransactionTemplate template = new TransactionTemplate(); template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED

How can one explicitly commit a spring db transaction when using declarative transaction management?

戏子无情 提交于 2019-12-13 15:26:45
问题 I am using Spring declarative database transaction management using the @Transactional annotation on my java methods. In one case, I would like to explicitly commit the current transaction (the one wrapping the currently executing method) prior to the method returning. How can this be done? I have tried auto wiring the current HibernateTransactionManager from the spring context and using that to commit, but it doesn't commit the transaction. The code I have tried is: transactionManager.commit