批量提取在EclipseLink中不起作用 [英] Batch Fetch is not working in EclipseLink

查看:91
本文介绍了批量提取在EclipseLink中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个简单的关联:

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

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

Using this code the addresses are not fetched in the result:

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();

在此地址中,地址被提取:

While in this one the addresses are fetched:

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 批注,但这些方法均无效。

Why the batch fetch is not working in the first? I'm using EclipseLink 2.5.1. I also tried the @BatchFetch annotation and neither of those approaches did work.

推荐答案

批处理获取提示告诉EclipseLink在获取关系时使用批处理,但不影响何时获取。由于该关系被标记为惰性,因此它仍然等待该关系被访问,但是当这样做时,它将使用批处理查询来返回通过初始查询引入的所有Employee的所有关联实体。联接提取是立即进行的,因为信息是随初始查询一起引入的,因此在它们之间放置间接值没有任何价值。

The batch fetch hint tells EclipseLink to use batching when it fetches the relationship, but doesn't influence when to fetch. Because the relationship is marked as lazy, it still waits for the relationship to be accessed, but when it does, it will use a batch query to return all associated entities for all Employee's brought in through the initial query. Join fetch is immediate because the information is brought in with the initial query, so there is no value in putting indirection in between.

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

If you want to load the relationship immediately, use

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

这篇关于批量提取在EclipseLink中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆