Maintaining a database change in isolation to the main transaction

Let's say I have the following code:

public void doSomething() { // begin transaction // do stuff 1 ... // update a row which must be committed now ... // do stuff 2 ... // commit transaction } 

I saved a lot of database work in one method to simplify the pseudocode. However, basically I have a series of work with the database, which I do not want to complete until the end. In the middle of the above transaction, I need to pass something to a string without passing the rest of the transaction. How can I do this little work without affecting the rest of the transaction?

0
java hibernate jpa
source share
1 answer

Usually you do this simply by grabbing a different connection and doing work on a different database connection. You may or may not need to manage database isolation levels to have the visibility you desire. So, for example, Propagation.REQUIRES_NEW works in Spring. (edit: notice that you marked the question β€œSleep mode.” Essentially, you create a completely new session / existing person and do separate work with this. This will lead to some unexpected results for the state of the object across borders. If you load something then from one and try to use it across the border to another that could explode on you. You need to be careful to properly manage it and keep track of what is being managed through the session.)

+2
source share

All Articles