How to move @Embedable collection to a dedicated entity class?

#1

Hello

I am using embedded objectdb in a 4 years old project. Over the years the data got bigger and now I want to make some performce improvements for some specific part of the code.

Lets say we have a Parent and Child class with onetomany relation

@Entity
class Parent {

   @Id
   Long id;

   @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL)
   List<Child> children;
}

@Embeddable
class Child{

   @Id
   Long id;

   // child does not have parent id
}

We have 1000 parents and some parents have more than 500K children.

Questions:

1. What is the most efficient way of retrieving all children of a specific parent for read only purposes (maybe using dto)?
When I load them by parent.getChildren() (lazy loading) in a @Transactional method, all children are loaded into entitymanager (because he wants to manage them) and it consumes too much memory and cpu. 

2. How should delete all children of a specific parent? Having a parent with 500K children, when I clear the list by parent.getChildren().clear(), it loads all children then empties the list and save the change. Is it possible to directly delete children list?

 

Thanks in advance

#2
  1. There is some overhead with every persistable object. Therefore, if you can reduce the number of objects that you read, e.g. by merging many small objects into fewer large objects, it could improve performance.
  2. maybe you should try children = null; or children = new ArrayList();
ObjectDB Support

Reply