We've got a Spring based web application that makes use of Hibernate to load/store its entities to the underlying database.
Since it's a backend application we not only want to allow our UI but also 3rd party tools to manually initiate DB transactions. That's why the callers need to
StartTransaction
method and in return get an ID that they can refer toCommitTransaction
method to signal to our backend that the transaction can be committed now (or in the negative case RollbackTransaction
will be called)So keeping in mind, that all database handling will be done internally by the Java persistence annotations, how can we open the transaction management to our UI that behaves like a 3rd party application that has no direct access to the backend entities but deals with data transfer objects only?
Transaction Interface in Hibernate In hibernate framework, we have Transaction interface that defines the unit of work. It maintains abstraction from the transaction implementation (JTA,JDBC). A transaction is associated with Session and instantiated by calling session.
To perform transaction management within the database using Spring Framework with Hibernate and Annotations, we need an access to the source code to edit it and add @Transactional Annotation to class and methods involved in performing the transaction operations.
From the Spring Reference: Programmatic transaction management
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With