eclipselink - 批量获取在 EclipseLink 中不起作用

标签 eclipselink

考虑这个简单的关联:

@Entity
public class Employee
{
    @OneToMany(fetch=FetchType.LAZY)
    private Set<Address> addresses;
}

使用此代码,不会在结果中获取地址:

Query query=entityManager.createQuery("select e from Employee e");
query.setHint("eclipselink.batch.type", "JOIN");
query.setHint("eclipselink.batch", "e.addresses");
List list=query.getResultList();

在这一过程中获取地址:

Query query=entityManager.createQuery("select e from Employee e");
query.setHint("eclipselink.join-fetch", "e.addresses");
List list=query.getResultList();

为什么批量获取第一次不起作用? 我正在使用 EclipseLink 2.5.1。我还尝试了 @BatchFetch 注释,但这些方法都不起作用。

最佳答案

批量获取提示告诉 EclipseLink 在获取关系时使用批处理,但不影响何时获取。由于关系被标记为惰性关系,因此它仍然等待关系被访问,但当它被访问时,它将使用批量查询返回通过初始查询引入的所有 Employee 的所有关联实体。连接获取是立即的,因为信息是通过初始查询引入的,因此在两者之间放置间接没有任何值(value)。

如果您想立即加载关系,请使用

query.setHint(QueryHints.LOAD_GROUP_ATTRIBUTE, "addresses");

关于eclipselink - 批量获取在 EclipseLink 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25383764/

相关文章:

java - Spring +JPA : object does not get fetched from the database

spring - 连接到mysql时随机拒绝访问

eclipselink - TopLink 11g 与 EclipseLink

java - JPA Eclipselink继承: update doesn't work

javax.ejb.TransactionRolledbackLocalException : Client's transaction aborted

java - 在 OSGI 应用程序中提供 EntityManager 的最佳实践

hql - 使用 EclipseLink 在 JPQL 中进行转换

java - JPA/Eclipselink @Cache 过期被忽略

jpa - org.eclipse.persistence.exceptions.QueryException : The primary key read from the row during the execution of the query was detected to be null

jpa - 如果执行 DDL 语句出错,则使 EcliseLink 失败