The following question comes from our Spring In the technology exchange group , A group friend's question about transaction rollback .
During the discussion , I'm trying to reproduce the problem scenarios raised by my friends , I found another situation that might confuse you .
At that time, the group said the results and reasons , But the scope of wechat group is limited , So write a separate article , Show it to you , By the way , Do you know anything about this .
The basic engineering of this problem I used before Spring Boot 2.x In the basic course 《 Use Spring Data JPA visit MySQL》 The case of .
You can go to the warehouse through
chapter3-4 Directory access infrastructure ：
In this project , Define a name
User Entity of ：
name Set the length to 5, So that you can get through insert Statement name Super long , Let it throw an exception , So you can test the trigger of the transaction .
In addition, the project also includes Spring Data Jpa Data access object of
UserRepository, Used to implement the User Data operations of entities , There is no specific code here .
Here the database uses MySQL 5.7, The storage engine is InnoDB, Use the default transaction level .
Let's adjust these four questions ：
Question 1 ：test1 Will it roll back ？
Question two ：test2 Will it roll back ？
Question 3 ：test3 Will it roll back ？（ Insert the second sentence name Super long ）
Question 4 ：test4 Will it roll back ？（ Insert the second sentence name Super long ）
Leave a message and tell me your answer , Will all four be rolled back ？ Search official account ： Program the ape DD, reply “ Transaction rollback ”, Get the right answer , See if your judgments are all right ？ If you want to collide with more interesting technical souls , reply ” Add group ” Can participate in our high quality communication group , Collision with more technological souls , Grow up together ！ More about why transactions don't roll back , Some of them were mentioned in the previous article , Those who are interested can have a look again Why is it added @Transactional annotation , The transaction did not roll back ？.