Is it beneficial to detach entities of large lists after querying, i.e. use a default pattern for those entities like:
// Find all
for List<Device> devices = em.createNamedQuery("find.*.devices", Device.class).getResultList();
// Detach all
for (Device d : devices) {
em.detach(d);
}
We could avoid some kinds of negative effects like erroneously update the database for entities considered as "read only" (which could be guaranteed) or save memory.
If you want to use a list without any updates in the database your can get the objects detached.
You have the following options:
Do not open a transaction if you are using programatic transaction. Notice that the transaction was not opened:
EntityManager em = EntityManagerFactory.createEntityManager();
List personList = em.query()
Mark your method as transaction not suported @TransactionAttribute(NOT_SUPPORTED)
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