'Do Jpa methods execute with or without transactions by default?
I am using JPA with hibernate for mysql.
I want to know whether jpa query methods will execute with or without transaction by default.
I am not using transaction management or locking of any sort.
Authoritative reference will be appreciated.
Thank you !
Solution 1:[1]
JPA with hibernate by default uses transaction. to be very precise it uses,
@TransactionAttribute(TransactionAttributeType.REQUIRED)
. If any other TransactionAttributeType
is not defined explicitly, this is what you get by default.
To learn more refer to this oracle
Solution 2:[2]
The individual jpa methods can be transactional, but if your logic uses several of these methods(several read/write operations) and you want them to run as an atomic operation in a multithreaded environment, you would still need to make the logic/method transactional to achieve that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Asgar |
Solution 2 |