spring-transactions

Problem in Handling Unit of work using Hibernate JPA

此生再无相见时 提交于 2019-11-28 01:46:38
I use Spring + Hibernate + JPA I need to handle the list of customers by inserting their orders. Here is the Unit of work : for(Customer customer: CustomerList) { List<Order> orderList = customer.getOrders(); for(Order order: OrderList) { //1. Insert order into ORDER table //If insert fails due to Duplicate key then no rollback and I follow steps 2 & 3. //If insert fails due to any reason except duplicate key then rollback all the previous transactions //2. select the order record (If any issue during selection then rollbackall the previous transactions) //3. Update the order If status of the

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

烂漫一生 提交于 2019-11-27 22:16:43
问题 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 = "

Prevent Dozer from triggering Hibernate lazy loading

烂漫一生 提交于 2019-11-27 18:24:44
I am using Spring transactions so the transaction is still active when POJO to DTO conversion occurs. I would like to prevent Dozer from triggering lazy loading, so that hidden sql queries never occur : all fetching has to be done explicitly via HQL (to get the best control on performances). Is it a good practice (I can't find it documented anywhere) ? How to do it safely ? I tried this before DTO conversion : PlatformTransactionManager tm = (PlatformTransactionManager) SingletonFactoryProvider.getSingletonFactory().getSingleton("transactionManager"); tm.commit(tm.getTransaction(new

@Transactional method calling another method without @Transactional anotation?

三世轮回 提交于 2019-11-27 10:27:25
I've seen a method in a Service class that was marked as @Transactional , but it was also calling some other methods in that same class which were not marked as @Transactional . Does it mean that the call to separate methods are causing the application to open separate connections to DB or suspend the parent transaction, etc? What's the default behavior for a method without any annotations which is called by another method with @Transactional annotation? Arun P Johny When you call a method without @Transactional within a transaction block, the parent transaction will continue to the new method

Spring transaction manager and multithreading

只谈情不闲聊 提交于 2019-11-27 07:10:49
问题 I am writing multithreading program in serviceImpl using Callable interface.I am using spring transaction manager.When update operation is executed in DB ,it is executed successfully .But the updated data is not reflected in DB. But When i run program without multithreading it is updated in DB . This is my configuration <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" /> <tx:method name="find*" propagation="NOT_SUPPORTED" /> <tx:method name="get*"

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

隐身守侯 提交于 2019-11-27 06:43:54
This question already has an answer here: How to flush data into db inside active spring transaction? 4 answers 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 spawned threads. @Transactional public void testAddAttachment() throws Exception{ final Contract c1 = contractDOD

Prevent Dozer from triggering Hibernate lazy loading

拈花ヽ惹草 提交于 2019-11-27 04:16:56
问题 I am using Spring transactions so the transaction is still active when POJO to DTO conversion occurs. I would like to prevent Dozer from triggering lazy loading, so that hidden sql queries never occur : all fetching has to be done explicitly via HQL (to get the best control on performances). Is it a good practice (I can't find it documented anywhere) ? How to do it safely ? I tried this before DTO conversion : PlatformTransactionManager tm = (PlatformTransactionManager)

Order of Spring @Transactional and Spring Security @PreAuthorize

↘锁芯ラ 提交于 2019-11-27 02:15:03
问题 So I have something like the following: public interface MyService { @PreAuthorize("hasPermission(T(Name).OBJ, T(Action).GET)") MyObj getObj(String id); } @Service public class MyServiceImpl implements MyService { @Override @Transactional public MyObj getObj(String id){ return dao.get(id); } } @Controller public class MyController { @Resource(name="myServiceImpl") private MyService service; public MyObj getObj(String id){ return service.getObj(id); } } When the method getObj(id) is called,

How to set autocommit to false in spring jdbc template

牧云@^-^@ 提交于 2019-11-27 02:11:45
问题 Currently I'm setting autocommit to false in spring through adding a property to a datasource bean id like below : <property name="defaultAutoCommit" value="false" /> But i need to add it specifically in a single java method before executing my procedure. I used the below code snippet. getJdbcTemplate().getDataSource().getConnection().setAutoCommit(false); But the above line was not setting autocommit to false? Am i missing anything ? or any alternative to set autocommit in a specific java

The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

为君一笑 提交于 2019-11-27 01:55:25
I am trying to configure JSF+Spring+hibernate and I'm tying to run a test but when I use this "tx:annotation-driven" on my application-context.xml file, I get this error: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven' Here is my application-context.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www