transactions

Nested @Transactional

对着背影说爱祢 提交于 2020-01-21 02:39:06
问题 Is it possible to nest @Transactional annotated methods in spring? Consider something like this: @Transactional public void a() { obj.b(); } @Transactional public void b() { // ... } What happens in such a case if I rollback in b() and rollback in a() ? 回答1: The second @Transactional annotation on method b() is not required because by default @Transactional has a propagation of REQUIRED , therefore methods called by method a() will be transactional. If you are looking to start a new

When I add @Async, entityManager.flush() will raise an exception

妖精的绣舞 提交于 2020-01-20 05:27:04
问题 I'm using Spring framework. The structure of my project is Controller ➡️ Service ➡️ Logic . I added @Transactional in Logic class. I am using EntityManager to do DB operations. After every db operation(select, update...), I am calling entityManager.flush() method. Everything is fine. But in order to improve performance, I added @Async in Service class. Then an exception is raised when I am calling entityManager.flush() . javax.persistence.TransactionRequiredException: no transaction is in

When I add @Async, entityManager.flush() will raise an exception

坚强是说给别人听的谎言 提交于 2020-01-20 05:26:46
问题 I'm using Spring framework. The structure of my project is Controller ➡️ Service ➡️ Logic . I added @Transactional in Logic class. I am using EntityManager to do DB operations. After every db operation(select, update...), I am calling entityManager.flush() method. Everything is fine. But in order to improve performance, I added @Async in Service class. Then an exception is raised when I am calling entityManager.flush() . javax.persistence.TransactionRequiredException: no transaction is in

How to configure and get session in Hibernate 4.3.4.Final?

耗尽温柔 提交于 2020-01-20 04:06:30
问题 I recently upgraded the version of my Hibernate to 4.3.4.Final. Based on Contextual Sessions configuration of Hibernate this new version is not based on ThreadLocal anymore. If what I have got so far is correct do I need to do anything to make it more efficient? if it is incorrect what should I do? I have no clue. Please note it is mentioned in documentation that: Hibernate offers three methods of current session tracking. The "thread" based method is not intended for production use; it is

Rails transaction doesn't input correct data

痞子三分冷 提交于 2020-01-17 12:34:07
问题 The Signup form in my app allows users to create an account - it also creates their user record and an accounts_users (has_many :through) record. Once they click submit, I am calling the 'setup_account' method to input several default values for the user's new account. With that said, the method is close to working but is inputting incorrect values for the three records where I manually assign values (i.e. :user_id => @user or :account_id => @account). The incorrect value for account_id and

Rails transaction doesn't input correct data

让人想犯罪 __ 提交于 2020-01-17 12:33:24
问题 The Signup form in my app allows users to create an account - it also creates their user record and an accounts_users (has_many :through) record. Once they click submit, I am calling the 'setup_account' method to input several default values for the user's new account. With that said, the method is close to working but is inputting incorrect values for the three records where I manually assign values (i.e. :user_id => @user or :account_id => @account). The incorrect value for account_id and

Foreign key problem with multiple db in one transaction

眉间皱痕 提交于 2020-01-17 06:03:18
问题 I have one db say DB1, on adding one column in one table (DB1.t1) on DB1, triggers and create replica of same row in table by same name (DB2.t1) in another DB2. Using the identity of inserted row I need to add some rows in another table (DB2.t2) in DB2. Problem is, I need to insert in DB1.t1 and DB2.t2 in one transaction. When try to do that, DB1.t1 inserts fine, but since it is not committed, DB2.t1 does not contain the row, so DB2.t2 could not insert new rows (missing foreign key), still

Overriding transactional Annotation Spring + hibernate

柔情痞子 提交于 2020-01-17 05:33:12
问题 I have this DAO: @Transactional("transactionManager") public class DAO{ public void save(String a){...} } I have this class: public class test{ ... @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void save(){ DAO.save("a"); DAO.save("b"); } } I want the "save" method to rollback when it throws an exception, but it doesn't seem to work when an exception occurs it does not rollback, what is the proper approach for this? All the other methods in the

How to control XAResource in inbound jca resource adapter for conversational transaction?

风流意气都作罢 提交于 2020-01-17 04:22:05
问题 Im writing an inbound resource adapter with JCA for a legacy EIS. The EIS does not support XA transactions. The messages however form a conversation that exist of multiple messages. Each message leads to an action that will be executed by the message endpoint. At the end of the conversation, a commit/rollback message will be received. At that moment all actions should be either committed or rolled back. Is there any way that I can manage the lifecycle myself from within the RA? 回答1:

Django 1.6 Transaction Management on large list of Model Objects

风流意气都作罢 提交于 2020-01-17 04:13:54
问题 Long question short : If I would need to loop through list of Model Objects, and save them individually, I am unsure how to go about that. To understand this correctly, Assuming, my Model Name = Foo example : Model Object : f1 = Foo 1 { name : foo, alias : Fooo 1, description : Fooo 1 } f2 = Foo 2 { name : foo_2, alias : Fooo, description : Fooo 2 } f3 = Foo 3 { name : foo_3, alias : Fooo 3, description : Fooo } Now what I would like to do is change : name for (Foo 1) alias for (Foo 2)