Transaction management in Hibernate in Spring Boot Interview questions | with example | Decoding code

Transaction management in Hibernate in Spring Boot Interview questions | with example | Decoding code

HomeCode DecodeTransaction management in Hibernate in Spring Boot Interview questions | with example | Decoding code
Transaction management in Hibernate in Spring Boot Interview questions | with example | Decoding code
ChannelPublish DateThumbnail & View CountDownload Video
Channel AvatarPublish Date not found Thumbnail
0 Views
In this code decoding video, we discussed transaction management in Spring Boot, which is a very important topic from an interview perspective.

Udemy course “Code Decode on Microservice k8s AWS CICD” link:
https://openinapp.co/udemycourse

Video of the course description:
https://yt.openinapp.co/dmjvd

Transaction Management Part 2: https://youtu.be/GqpQ3J40Op8

How to implement transactions in Spring/Hibernate
If you integrate your Hibernate into a Spring Boot project, you do not need to use Hibernate transaction management because you can leave it to Spring's declarative transaction management using the @Transactional annotation.

Using the @Transactional annotation.

What is @Transactional?
We can use @Transactional to enclose a method in a database transaction.

It enables us
reproduction,
Insulation,
time out,
read-only and
Rollback
Terms of our transaction.

How does @Transactional work internally?
Spring creates a proxy or manipulates the class's bytecode to manage the creation, commit, and rollback of the transaction.

If we have a method like callMethod and mark it as @Transactional, Spring wraps the invocation@Transactional method with some transaction management code called:

createTransactionIfNeeded();
attempt {
Add Employee();
commitTransactionAfterReturning();
} Catch (Exception) {
rollbackTransactionAfterThrowing();
throw exception;
}

How to use @Transational
You can use this note, in order from lowest to highest priority, for the following:
Interface,
Super great,
Class,
interface method,
Superclass method and
Method.

The EmployeeService class is provided with the settings for a read-only transaction at class level.
but the @Transactional annotation of the addEmployee() method in the same class takes precedence over the transaction settings defined at the class level.

Normally, it is not recommended to set @Transactional on the interface.
it is acceptable for cases like @Repository with Spring Data. We can put the annotation on a class definition to override the transaction setting of the interface/superclass:

What is a transaction?
Transactions manage the changes you make in one or more systems.
These can be databases, message brokers or any other type of software system.
The main goal of a transaction is to provide ACID properties to ensure the consistency and validity of your data.

What is an ACID transaction?
ACID is an acronym that stands for atomicity, consistency, isolation and durability:

Atomicity describes an all-or-nothing principle. Either all operations within the transaction are executed or none are. This means that if you complete the transaction successfully, you can be sure that all operations have been executed. In addition, you can abort a transaction and undo all operations if an error occurs.

The consistency property ensures that your transaction moves a system from one consistent state to another consistent state. This means that either all operations have been rolled back and the data has been returned to its original state, or that the changed data has passed all consistency checks. In a relational database, this means that the changed data must pass all constraint checks defined in your database, such as foreign key or unique constraints.

Isolation means that changes you make within one transaction are not visible to other transactions until you successfully commit them.

Persistence ensures that your applied changes persist.

Most frequently asked Core Java interview questions and answers: https://youtube.com/playlist?list=PLyHJZXNdCXscoyL5XEZoHHZ86_6h3GWE1
Advanced Java Interview Questions and Answers: https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd

Questions and answers about the Java 8 interview: https://youtube.com/playlist?list=PLyHJZXNdCXsdeusn4OM33415DCMQ6sUKy

Questions and answers about the Hibernate interview:
https://youtube.com/playlist?list=PLyHJZXNdCXsdC-p2186C6NO4FpadnCC_q

Spring Boot Interview Questions and Answers:
https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd

Angular playlist: https://www.youtube.com/watch?v=CAl7RQSdq2Q&list=PLyHJZXNdCXsfxRtDwtGkDD_lLfTWc1g0i
SQL playlist: https://www.youtube.com/playlist?list=PLyHJZXNdCXse86eLuwy5uZohd_bddE9Ni

GIT: https://youtube.com/playlist?list=PLyHJZXNdCXscpl6pxOnL2lRWJlzvzjyZE

Subscriber and follow code decoding
Subscriber Code Decode: https://www.youtube.com/c/CodeDecode?sub_confirmation=1
LinkedIn: https://www.linkedin.com/in/codedecodeyoutube/
Instagram: https://www.instagram.com/codedecode25/

#transaction #springboot #codedecode

Please take the opportunity to connect with your friends and family and share this video with them if you find it useful.