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