I am reading the transaction management Using Spring framework. In first combination I used Spring + hiberante and used Hibernate's API's to control the transaction (Hibenate API's). Next, I wanted to test using @Transactional
annotation, and it did work.
I am getting confused on:
Do JPA , JTA, Hibernate have their "own" way of transaction management. As an example, consider if I use Spring + Hibernate, in that case would u use "JPA" transactions?
Like we have JTA, is it true to say we can use Spring and JTA to control transactions?
The
@Transactional
annotation, is that specific to Spring Framework? From what I understood, this annotation is Spring Framework specific. If this is correct, is@Transactional
using JPA/JTA to do the transaction control?
I do read online to clear my doubts, however something I don't get direct answer. Any inputs would be great help.
@Transactional
in case ofSpring->Hibernate
usingJPA
i.e.@Transactional
Annotations should be placed around all operations that are inseparable.So lets take example:
We have 2 model's i.e.
Country
andCity
. Relational Mapping ofCountry
andCity
model is like one Country can have multiple Cities so mapping is like,Here Country mapped to multiple cities with fetching them Lazily. So here comes role of
@Transactinal
when we retrieve Country object from database then we will get all the data of Country object but will not get Set of cities because we are fetching cities LAZILY.When we want to access Set of Cities from country object then we will get null values in that Set because object of Set created only this Set is not initialize with there data to get values of Set we use
@Transactional
i.e.,So basically
@Transactional
is Service can make multiple call in single transaction without closing connection with end point.Hope this will helpful to you.