spring-transactions

Transactional annotation to rollback for every checked exception - with AspectJ

你。 提交于 2020-08-09 18:28:32
问题 I would like to use @Transactional annotation ( org.springframework.transaction.annotation ) for transactions management. I need the rollback to occur for every exception (not just unchecked exceptions), so I use: @Transactional (rollbackFor = Exception.class) I use AspectJ mode, and it's working fine. The problem is, I don't want the developer to have to add the rollbackFor attribute every time. I found this answer, that suggests to extend the @Transactional annotation, like so: @Target(

SpringFramework: @Transactional(readOnly = true) not working with h2

非 Y 不嫁゛ 提交于 2020-06-27 09:10:26
问题 I am doing transaction testing with the SpringFramework. I have the following classes. UserService.class @Transactional public interface UserService { void add(User user); @Transactional(readOnly = true) User get(String id); @Transactional(readOnly = true) List<User> getAll(); void deleteAll(); void update(User user); } UserServiceImpl.class public class UserServiceImpl implements UserService { // skip some methods @Override public void update(User user) { userDao.update(user); } }

LazyInitializationException trying to get lazy initialized instance

守給你的承諾、 提交于 2020-05-11 07:42:49
问题 I see the following exception message in my IDE when I try to get lazy initialized entity (I can't find where it is stored in the proxy entity so I can't provide the whole stack trace for this exception): Method threw 'org.hibernate.LazyInitializationException' exception. Cannot evaluate com.epam.spring.core.domain.UserAccount_$$_jvste6b_4.toString() Here is a stack trace I get right after I try to access a field of the lazy initialized entity I want to use: org.hibernate

LazyInitializationException trying to get lazy initialized instance

你。 提交于 2020-05-11 07:42:25
问题 I see the following exception message in my IDE when I try to get lazy initialized entity (I can't find where it is stored in the proxy entity so I can't provide the whole stack trace for this exception): Method threw 'org.hibernate.LazyInitializationException' exception. Cannot evaluate com.epam.spring.core.domain.UserAccount_$$_jvste6b_4.toString() Here is a stack trace I get right after I try to access a field of the lazy initialized entity I want to use: org.hibernate

Self-invocation behaviour in @Configuration vs. @Component classes

 ̄綄美尐妖づ 提交于 2020-02-22 07:46:48
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

Self-invocation behaviour in @Configuration vs. @Component classes

痴心易碎 提交于 2020-02-22 07:46:45
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

Listener on transaction start

一世执手 提交于 2020-02-01 05:19:53
问题 I am looking for a clean solution to have a listener for transaction start. That means I would like the listener to be a bean (component) in the spring context that would receive an event on transaction start from TransactionPlatformManager or Hibernate Session or something similar, at the point where a new transaction is started. Something along: @Component class TransactionListener implements ?? { @Autowired private Something x; public void onTransactionBegin(...) { x.doSomething() } } To

Spring transactionManager is Rolling back, while testexception=[null]!

可紊 提交于 2020-01-23 08:55:54
问题 Why is the transaction being rolled back while there is no Exception ? The object is not being saved. I have defined the transaction parameters like: @Transactional(value = "transactionManager", timeout = 30, rollbackFor = java.lang.Exception.class)`. This is what logs say about the transaction. org.springframework.test.context.transaction.TransactionalTestExecutionListener endTransaction INFO: Rolled back transaction after test execution for test context [TestContext@51e2a069 testClass =

Transaction Management using Hibernate with weblogic

允我心安 提交于 2020-01-20 08:46:08
问题 Our application is deployed on weblogic we use Hibernate and spring The session factory is created through a user defined class which creates SessionFactories by reading the hibernate.cfg.xml file So these are the steps : Our custom class is defined in spring application context and we inject the format of theCFG xml file in this class constructor : <bean id="myCustomFactoryCreator" class="com.xyz.CustomFactoryCreator" singleton="true"> <constructor-arg> <bean class="org.springframework.beans

Spring Data JPA Transaction - No Transaction in progress - Spring Data Neo4j

北城余情 提交于 2020-01-17 01:58:06
问题 I think i'm missing something obvious. Iam trying to make a entity persist into a database via a JUnit Test case, however it doesnt seem to be persisting due to no active transaction. Configuration: @Configuration @EnableTransactionManagement public class TransactionConfig { @Inject private EntityManagerFactory entityMangerFactory; @Bean public JpaTransactionManager transactionManager(){ return new JpaTransactionManager(entityMangerFactory); } TestCase: @RunWith(SpringJUnit4ClassRunner.class)