transactional

Transactional annotation avoids services being mocked

旧城冷巷雨未停 提交于 2019-11-27 05:09:17
I have a drools rule file which uses service classes in the rules. So one rule does something like this: eval(countryService.getCountryById(1) != null) In a validationservice that is annotated with @service and @Transactional(propagation=Propagation.SUPPORTS) the drools file is used in a statelessKnowledgebase and facts are added that should be used in the drool. Once that is done the session.execute(facts) is invoked and the rule engine starts. In order to test the rules I would like to stub the countryService.getCountryById(). No big problem using mockito. Done this for other service that

How to use spring transaction in multithread

我与影子孤独终老i 提交于 2019-11-27 03:56:18
I have a method as below: ClassA.java @Transactional public void methodA(){ ExecutorService executorService = Executors.newFixedThreadPool(4); executorService.execute(new Runnable() { public void run() { classB.methodB(); } }); } ClassB.java @Transactional public void methodB(){ updateDB(); } Can the methodB work well? Per my understanding, methodB will attach the transaction of methodA, what if methodA exits before methodB? I guess only methodA can be commited by the transaction. But methodB will not commit because the transaction commited before. Can I use @Transactional(propagation =

Transactional saves without calling update method

纵然是瞬间 提交于 2019-11-27 00:56:29
I have a method annotated with @Transactional. I retrieve an object from my Oracle DB, change a field, and then return from the method. I forgot to save the object, but discovered that the database gets updated anyway. applicationContext <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> my method @Transactional public void myMethod(long id) { MyObject myObj = dao.getMstAttributeById(id); myObj.setName("new name"); //dao.update(myObj); } my question is why

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

For web MVC Spring app should @Transactional go on controller or service?

℡╲_俬逩灬. 提交于 2019-11-26 19:46:45
问题 For WebApplicationContext, should I put @Transactional annotations in the controller or in services? The Spring docs have me a bit confused. Here is my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2

Why we shouldn't make a Spring MVC controller @Transactional?

江枫思渺然 提交于 2019-11-26 19:37:50
There are already a few questions about the topic, but no response at all really provides arguments in order to explain why we shouldn't make a Spring MVC controller Transactional . See: Transaction not working correctly - Spring/MyBatis For web MVC Spring app should @Transactional go on controller or service? Making Spring 3 MVC controller method Transactional Spring MVC Controller Transactional So, why? Is there insurmountable technical issues? Is there architectural issues? Is there performance/deadlock/concurrency issues? Are sometimes multiple separate transactions required? If yes, what

Showing a Spring transaction in log

倖福魔咒の 提交于 2019-11-26 15:16:03
问题 I configured spring with transactional support. Is there any way to log transactions just to ensure I set up everything correctly? Showing in the log is a good way to see what is happening. 回答1: in your log4j.properties (for alternative loggers, or log4j's xml format, check the docs) Depending on your transaction manager, you can set the logging level of the spring framework so that it gives you more info about transactions. For example, in case of using JpaTransactionManager , you set log4j

@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

Spring @Transactional - isolation, propagation

此生再无相见时 提交于 2019-11-26 11:27:14
Can someone explain what isolation & propagation parameters are for in the @Transactional annotation via real-world example? Basically when and why I should choose to change their default values. Johan Sjöberg Good question, although not a trivial one to answer. Propagation Defines how transactions relate to each other. Common options: Required : Code will always run in a transaction. Creates a new transaction or reuses one if available. Requires_new : Code will always run in a new transaction. Suspends the current transaction if one exists. Isolation Defines the data contract between

Transactional annotation avoids services being mocked

試著忘記壹切 提交于 2019-11-26 11:26:55
问题 I have a drools rule file which uses service classes in the rules. So one rule does something like this: eval(countryService.getCountryById(1) != null) In a validationservice that is annotated with @service and @Transactional(propagation=Propagation.SUPPORTS) the drools file is used in a statelessKnowledgebase and facts are added that should be used in the drool. Once that is done the session.execute(facts) is invoked and the rule engine starts. In order to test the rules I would like to stub