spring-transactions

Why @Scheduled annotation doesn't work with @Transaction annotation. Spring Boot

落花浮王杯 提交于 2019-11-29 04:19:18
I have a question: Why when we annotate method with @Scheduled and @Transaction , transaction doesn't work? I know that the @Scheduled call my class instead of proxy class that created by Spring, but can't understand this behavior. import org.springframework.scheduling.annotation.Scheduled; import org.springframework.transaction.annotation.Transactional; @Service public class UserServiceImpl implements UserService { @Override @Scheduled(fixedRateString = "${somestring}",initialDelayString = "${anotherstring}") @Transactional public void doSomething() { } } I have two solutions of this problem:

Hibernate collection is not associated with any session

房东的猫 提交于 2019-11-29 01:21:12
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) { Integration integration = integrationDao.get(integrationId); //not all integrations have to have

Spring JPA repository transactionality

◇◆丶佛笑我妖孽 提交于 2019-11-28 23:16:20
1 quick question on Spring JPA repositories transactionality. I have a service that is not marked as transactional and calls Spring JPA repository method userRegistrationRepository.deleteByEmail(email); And it is defined as @Repository public interface UserRegistrationRepository extends JpaRepository<UserRegistration, Long> { UserRegistration findByEmail(String email); void deleteByEmail(String email); } The problem is that it fails with " No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call; nested exception is javax.persistence

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

一笑奈何 提交于 2019-11-28 14:11:18
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.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /> <property

Spring @Transactional method - participating transaction

烈酒焚心 提交于 2019-11-28 11:33:04
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? 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 transactional annotation has no effect } @Transactional public void doSomeThingElse(){ } you are calling the proxy

Handle spring-data-rest application events within the transaction

依然范特西╮ 提交于 2019-11-28 08:26:22
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 = LoggerFactory.getLogger(TestEventListener.class); @Override protected void onBeforeCreate(Object entity)

How to flush data into db inside active spring transaction?

主宰稳场 提交于 2019-11-28 07:38:17
I want to test hibernate session's save() method using spring testing framework. @Test method is : @Test @Transactional public void testSave() { User expected = createUser(); getGenericDao().currentSession().save(expected); User actual = getUser(generatedId); assertUsersEqual(expected,actual); } I want to flush user into database. I want my user to be in database after this method getGenericDao().currentSession().save(expected); Then I want to go to database using spring data framework and fetch this saved user by next line: User actual = getUser(generatedId); I tried to use hibernate flush

Why doesn't Spring's @Transactional work on protected methods?

安稳与你 提交于 2019-11-28 04:37:42
问题 From Does Spring @Transactional attribute work on a private method? When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. I can think of good reasons to exclude private and package-private methods, but why won't protected methods behave

What is the difference between defining @Transactional on class vs method

房东的猫 提交于 2019-11-28 03:46:54
Case1 @Transactional public class UserServiceImpl implements UserService { ................... public void method1(){ try{ method2(); }catch(Exception e){ } } public void method2(){ } } Case2 public class UserServiceImpl implements UserService { ................... public void method1(){ try{ method2(); }catch(Exception e){ } } @Transactional public void method2(){ } } In case1 if any exception occurs it rollback is working, but in case 2 it's not working. Is there any performance issues if I follow the case1? niekname In case 1 @Transactional is applied to every individual method. In case 2

Why do spring/hibernate read-only database transactions run slower than read-write?

拈花ヽ惹草 提交于 2019-11-28 03:06:57
I've been doing some research around the performance of read-only versus read-write database transactions. The MySQL server is remote across a slow VPN link so it's easy for me to see differences between the transaction types. This is with connection pooling which I know is working based on comparing 1st versus 2nd JDBC calls. When I configure the Spring AOP to use a read-only transaction on my DAO call, the calls are 30-40% slower compared to read-write: <!-- slower --> <tx:method name="find*" read-only="true" propagation="REQUIRED" /> ... // slower @Transaction(readOnly = true) Versus: <!--