JPA + Eclipselink - Lazy Loading with closed Entitymanager

Asked

Viewed 157 times

2

I am using Eclipselink as JPA preview in a Java SE project. I have correctly configured Weaving to allow Lazy Loading.

Unlike Hibernate (which launches Lazyinitializationexception), Eclipselink manages to obtain the proxy for a LAZY relationship, even with the closed Entitymanager. To run this query, it gets a new pool connection.

Does anyone know if there are any settings that disable or change the behavior of this feature? I need to receive a null value or an exception when trying to access an unladen attribute, just like Hibernate does.

Example:

List<Cliente> clientes = entityManager.createQuery("from Cliente c", Cliente.class).getResultList();
entityManager.close(); // fechando o EntityManager

for (Cliente cliente : clientes) {
    cliente.getEndereco(); // Aqui o EclipseLink executa uma query para trazer o relacionamento.
}

Thank you.

  • Rodolpho, I don’t have much experience with Eclipselink, but isn’t it precisely Weaving that creates the proxy for Lazy relationships? There are some properties related to the behavior of Lazy load here: https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Disabling_Weaving_with_Persistence_Unit_Properties, maybe some help you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.