Home » Support » Forum » Using of Second Level Cache

Using of Second Level Cache

#1

In our use case we want to find some entity types always again very quickly by primary key or query in many short transactions.

The entity MyEntity1 and its relationships to MyEntity2/MyEntity3 was load and the entity MyEntity1 is taken in the second level cache, the other entity types not. Are the relationships to MyEntity2/MyEntity3 still always referenced although the entity manager is closed, so that the memory for MyEntity2 and MyEntity3 can never be released by garbage collector?

class MyEntity1 {   
    @OneToOne
    private MyEntity2 myEntity2;  

    @OneToMany
    private List<MyEntity3> list;

}

#2

The 2nd level cache stores object data (byte[]) rather than live entity objects, so references from a MyEntity1 instance to MyEntity2 and MyEntity3 objects are stored in the 2nd level cache as object IDs (PK) encoded in the byte[] of a MyEntity1 instance.

When you retrieve a MyEntity1 its fields may be initialised as null / empty list, unless eager fetch is used. Anyway, when the MyEntity2 and MyEntity3 instances are needed they are fetched from the 2nd level cache if available.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login