javadb4o

Implement a relation using db4o


For testing purposes i want to implement a relationship between two java classes for instance student and exam. How can i make relationships using db4o. I don't have much experience with this DB - system, just worked with hibernate so far.


Solution

  • db4o is a object oriented database so all you need to do is to define a field in Exam class that references Student.

    For instance?

    class Exam
    {
       List<Student> students;
    }
    

    This way whenever you save / retrieve an Exam instance db4o will take care of retrieving the students (there are some limits related to how deep db4o will follow the rabbit hole, i.e, how many levels of reference will db4o load but you can control this and in general the default configuration has a good compromise regarding usage easiness / memory consumption / performance