【发布时间】:2015-12-18 02:26:58
【问题描述】:
我在 Java SE 项目中使用 EclipseLink 作为 JPA 提供程序。我已正确配置编织以允许延迟加载。
与 Hibernate(抛出 LazyInitializationException)不同,EclipseLink 可以获取 LAZY 关系的代理,即使是关闭的 EntityManager。要运行此查询,它会从池中获取一个新连接。
是否有一些设置会禁用或更改此功能的行为?在尝试访问未加载的属性时,我需要获取空值或异常,例如 Hibernate。
例子:
List<Customer> customers = entityManager.createQuery("from Customer c", Customer.class).getResultList();
entityManager.close(); // Closing the EntityManager
for (Customer customer: customers) {
customer.getAddress(); // Here EclipseLink executes a query to get the relationship.
}
谢谢。
【问题讨论】:
标签: java jpa jdbc eclipselink lazy-loading