spring-transactions

Spring JPA repository transactionality

五迷三道 提交于 2019-11-27 01:50:31
问题 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

How to flush data into db inside active spring transaction?

a 夏天 提交于 2019-11-27 01:38:29
问题 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

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

◇◆丶佛笑我妖孽 提交于 2019-11-27 00:08:20
问题 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

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

杀马特。学长 韩版系。学妹 提交于 2019-11-26 23:57:08
问题 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

Problem in Handling Unit of work using Hibernate JPA

♀尐吖头ヾ 提交于 2019-11-26 23:35:09
问题 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

Spring - Is it possible to use multiple transaction managers in the same application?

て烟熏妆下的殇ゞ 提交于 2019-11-26 21:41:53
I'm new to Spring and I'm wondering if its possible to use numerous transaction managers in the same application? I have two data access layers - one for both of the databases. I'm wondering, how do you go about using one transaction managers for one layer and different transaction manager for the other layer. I don't need to perform transactions across both databases - yet. But I do need perform transactions on each database individually. I've created an image to help outline my problem: Here is my application context configuration: <beans xmlns="http://www.springframework.org/schema/beans"

Spring Transactions and hibernate.current_session_context_class

末鹿安然 提交于 2019-11-26 20:36:07
I have a Spring 3.2 application that uses Hibernate 4 and Spring Transactions. All the methods were working great and I could access correctly the database to save or retrieve entities. Then, I introduced some multithreading, and since each thread was accessing to db I was getting the following error from Hibernate: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions I read from the web that I've to add <prop key="hibernate.current_session_context_class">thread</prop> to my Hibernate configuration, but now every time I try to access the db I get:

@Transactional method calling another method without @Transactional anotation?

六月ゝ 毕业季﹏ 提交于 2019-11-26 15:10:53
问题 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? 回答1: When you call a method without

The matching wildcard is strict, but no declaration can be found for element &#39;tx:annotation-driven&#39;

ⅰ亾dé卋堺 提交于 2019-11-26 09:49:26
问题 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

Spring - Is it possible to use multiple transaction managers in the same application?

柔情痞子 提交于 2019-11-26 08:02:52
问题 I\'m new to Spring and I\'m wondering if its possible to use numerous transaction managers in the same application? I have two data access layers - one for both of the databases. I\'m wondering, how do you go about using one transaction managers for one layer and different transaction manager for the other layer. I don\'t need to perform transactions across both databases - yet. But I do need perform transactions on each database individually. I\'ve created an image to help outline my problem