Do Jpa methods execute with or without transactions by default?

Viewed 95

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 !

2 Answers

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.

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

Related