Skip to content
Advertisement

Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities?

Does having TransactionAttributeType.NOT_SUPPORTED on every DB lookup method makes sense? I don’t see the point in having the entity attached if it’s not going to execute an update.

JavaScript

Does it still end up in the cache?

The only time it seems useful to use the REQUIRED transcation propagation is when an update is required:

JavaScript

Other than that I don’t really see the point.

Advertisement

Answer

No, it doesn’t make sense to use the NOT_SUPPORTED transaction propagation for read-only queries, but it makes a lot of sense to use the default REQUIRED transaction propagation. You also need a transaction for reading data. The database always uses a transaction, no matter if you specify it or not.

Using an explicit transaction allows you to group several statements in a single transaction, and, if you are using Hibernate, you might avoid the aggressive connection release overhead.

Just because JPA allows you to execute read queries without a transaction, it doesn’t mean you have to do it this way.

The NOT_SUPPORTED mode is useful when you want to execute a service method outside of the current transaction scope. For example, when you have methods that don’t need a transaction at all (e.g sending an email) so that you avoid the overhead of starting/ending a transaction context.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement