JPA + EclipseLink - Lazy Loading with EntityManager closed

2

I'm using EclipseLink as a JPA provider in a Java SE project. I have already set up weaving correctly to allow Lazy Loading.

Unlike Hibernate (which launches LazyInitializationException), EclipseLink can get the proxy of a LAZY relationship, even with the EntityManager closed. To execute this query, it gets a new connection from the pool.

Does anyone know if there is a setting that disables or changes the behavior of this feature? I need to get a null value or an exception when trying to access an unloaded 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.

    
asked by anonymous 19.09.2015 / 01:18

0 answers