Memory use in OneToMany relationships

#1

Hello everyone,

I have a question regarding the OneToMany / ManyToOne Relationship in ObjectDB.

So imaging following setup:

We have class A which holds an collection (List, Arrray ...) of class B.

In a more usual DB like MySQL with a seperate server we first query for the Entitys of class A and than get Entitys of class B as we need them.

How does Object DB handle this. Does it load all Instances of B into Memory when we query for A.

Example:

    Class Pet holds a Collection of Class PicData.

    Class PicData holds a byte[] (a picture) with some more data about that picture.

If we assume we load 10 Pet from the DB into memory and assume each Pet has 10 Pictures would that mean that we automatically load 100 byte[]'s worth of pictures into memory?

I would assume so and can this be worked around by having PicData a reference to the Pet like the more usual FK points to PK ?

With kind regards,

Lucy

PS: sorry my english isn't the best :/

#2

By default, when a Pet object is loaded, the PicData objects are not loaded yet. You can change this behaviour by specifying EAGER load (the default for collections is LAZY).

There is a difference between using reflection mode and enhancement mode. In enhancement mode, each PicData is loaded when it is accessed. In reflection mode, when the collection is accessed, all the PicData objects are loaded.

This exact behaviour may be changed in future versions, but the JPA rules remain: With EAGER you know that the referenced objects are loaded immediately, but LAZY is only a tip for the implementation.

ObjectDB Support

Reply