Caching eclipselink和一致性缓存预热:未初始化child

Caching eclipselink和一致性缓存预热:未初始化child,caching,eclipselink,lazy-evaluation,oracle-coherence,batch-fetching,Caching,Eclipselink,Lazy Evaluation,Oracle Coherence,Batch Fetching,我将eclipselink与一致性分布式缓存和关系数据库Toplink网格-网格缓存配置一起使用。现在,我正在尝试尽可能高效地执行缓存预热,以减少将来与数据库的连接数量 我有一个非常简单的数据模型:一个与孩子的实体MagicCard具有单向一对多关系的父实体Person @Entity @Customizer(GridCacheCustomizer.class) public class Person implements Serializable { @Id private i

我将eclipselink与一致性分布式缓存和关系数据库Toplink网格-网格缓存配置一起使用。现在,我正在尝试尽可能高效地执行缓存预热,以减少将来与数据库的连接数量

我有一个非常简单的数据模型:一个与孩子的实体MagicCard具有单向一对多关系的父实体Person

@Entity
@Customizer(GridCacheCustomizer.class)
public class Person implements Serializable {
    @Id
    private int Id;

    @Version
    protected int version;

    private String surname;
    private String name;

    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY , orphanRemoval=true )
    @CascadeOnDelete 
    @JoinColumn(name="person_id_ref")
    private List<MagicCard> cardList;
}

@Entity
@Customizer(GridCacheCustomizer.class)
public class MagicCard implements Serializable {

    @Id
    private int Id;

    private String descr;

    @Version
    protected int version;
}
此搜索似乎正确地填充了这两个实体的一致性缓存。以下日志来自一个示例,其中4个人分别持有4张、3张、1张和0张卡:

[EL Fine]: cache: Coherence(Person)::Get: [1, 2, 3, 4] result size: 4
[EL Fine]: cache: Coherence(Person)::ConditionalPut: 1 value: entities.Person hashcode: 558082331
[EL Fine]: cache: Coherence(MagicCard)::Get: [3, 1, 2, 4, 5, 6, 7, 8] result size: 8
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 3 value: entities.MagicCard hashcode: 321885278
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 1 value: entities.MagicCard hashcode: 1206609130
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 2 value: entities.MagicCard hashcode: 1405610448
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 4 value: entities.MagicCard hashcode: 948640159
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 5 value: entities.MagicCard hashcode: 2122449463
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 6 value: entities.MagicCard hashcode: 714661629
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 7 value: entities.MagicCard hashcode: 905115332
[EL Fine]: cache: Coherence(MagicCard)::ConditionalPut: 8 value: entities.MagicCard hashcode: 127827822
[EL Fine]: cache: Coherence(Person)::ConditionalPut: 2 value: entities.Person hashcode: 1268451305
[EL Fine]: cache: Coherence(Person)::ConditionalPut: 3 value: entities.Person hashcode: 1535800224
[EL Fine]: cache: Coherence(Person)::ConditionalPut: 4 value: entities.Person hashcode: 164901111

*****************
cache : class com.tangosol.coherence.component.util.SafeNamedCache -- Person
.------- cache Person size 4
| KEY : 1 - VALUE TYPE : oracle.eclipselink.coherence.integrated.cache.wrappers.entities.Person_Wrapper
| KEY : 3 - VALUE TYPE : oracle.eclipselink.coherence.integrated.cache.wrappers.entities.Person_Wrapper
| KEY : 4 - VALUE TYPE : oracle.eclipselink.coherence.integrated.cache.wrappers.entities.Person_Wrapper
| KEY : 2 - VALUE TYPE : oracle.eclipselink.coherence.integrated.cache.wrappers.entities.Person_Wrapper
'--------------------

cache : class com.tangosol.coherence.component.util.SafeNamedCache -- MagicCard
.------- cache MagicCard size 8
| KEY : 1 - VALUE TYPE : Entities.MagicCard
| KEY : 7 - VALUE TYPE : Entities.MagicCard
| KEY : 3 - VALUE TYPE : Entities.MagicCard
| KEY : 5 - VALUE TYPE : Entities.MagicCard
| KEY : 4 - VALUE TYPE : Entities.MagicCard
| KEY : 6 - VALUE TYPE : Entities.MagicCard
| KEY : 2 - VALUE TYPE : Entities.MagicCard
| KEY : 8 - VALUE TYPE : Entities.MagicCard
'--------------------
*****************
接下来,我尝试使用EntityManager查找特定的人或特定的卡

System.err.println("*** FINDING PERSON WITH ID=1 ***");
Person p = em1.find(Person.class, id);
System.out.println("[PERSON] " + p.toString());
并成功执行缓存搜索,如预期:

*** FINDING PERSON WITH ID=1 ***
[EL Fine]: cache: Coherence(Person)::Get: 1 result: entities.Person hashcode: 2132249404
[PERSON] Person [Id=1, name=x, surname=y]
但是,当我尝试查找某人的卡片时,eclipselink需要执行额外的数据库选择,我认为我应该通过批量获取来避免这些:

System.err.println("*** FINDING CARDS FROM PERSON WITH ID=1 ***");
Person p = em1.find(Person.class, id);
List<MagicCard> cards = p.getMagicCardList();
System.out.println(cards.size() + " cards found:\n");

---

[EL Fine]: cache: Coherence(Person)::Get: 1 result: entities.Person hashcode: 138084761
[EL Fine]: sql: Connection(278533322)--SELECT ID, DESCR, VERSION FROM MAGICCARD WHERE (person_id_ref = ?)
    bind => [1]
[EL Fine]: cache: Coherence(MagicCard)::Get: [3, 1, 2, 4] result size: 4
4 cards found
我希望它能从一致性缓存中获得卡片列表,而不是从数据库中,因为我以前用每个人的卡片填充了前者。我能让它按我的意愿工作的唯一方法是将@OneToMany FetchType更改为Earge,但我希望避免这种更改,因为它会对我系统的另一部分产生负面影响

批处理和加载提示不应该初始化父对象中的子对象吗?还是我做错了什么?有没有其他/更好的方法来实现这一点


提前感谢

通过使用批取,您可以确保所有需要的MagicCard都存在于相干缓存中,但我认为相干缓存不会缓存对象关系。相反,TopLink包装器用于获取它们——对于OneToMany,这意味着查询。因为这种类型的查询不是基于主键的,所以它必须转到数据库,正如您所看到的那样。然后,它从一致性缓存中获取数据,而不是构建实体。感谢您的响应。我知道这些关系是由Toplink/EL获取的。但是,Person缓存中的元素是包装结果,而不是简单的POJO Person对象。因此,他们应该怎样做?包含所需的关系信息。如果无法单独从一致性缓存中检索数据,那么如何通过将FetchType更改为Earge而突然实现?
*** FINDING PERSON WITH ID=1 ***
[EL Fine]: cache: Coherence(Person)::Get: 1 result: entities.Person hashcode: 2132249404
[PERSON] Person [Id=1, name=x, surname=y]
System.err.println("*** FINDING CARDS FROM PERSON WITH ID=1 ***");
Person p = em1.find(Person.class, id);
List<MagicCard> cards = p.getMagicCardList();
System.out.println(cards.size() + " cards found:\n");

---

[EL Fine]: cache: Coherence(Person)::Get: 1 result: entities.Person hashcode: 138084761
[EL Fine]: sql: Connection(278533322)--SELECT ID, DESCR, VERSION FROM MAGICCARD WHERE (person_id_ref = ?)
    bind => [1]
[EL Fine]: cache: Coherence(MagicCard)::Get: [3, 1, 2, 4] result size: 4
4 cards found