There are two problems in your test. After fixing these errors the relationship between the parent and the child is created as expected.
The first problem, in JPA you can use field access or property access, but mixing them is not allowed. If you annotate a field with @Id then your are using field access. In that case, other annotations should also be on fields rather than on property methods.
Accordingly your Parent class should be defined as:
@Entity
public static class Parent {
@Id
private int parentID;
private int childFK;
@OneToMany(orphanRemoval=true)
// @JoinColumn(name="childFK") ignored by ObjectDB
Set<Child> children;
public Parent(int p,int c) {
this.parentID = p;
this.childFK = c;
}
public Set<Child> getChildren(){
return children;
}
}
The second problem is that the main method persists two objects, a parent and a child, but without connecting them. You have to add a line of code for connecting these two objects:
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Parent p = new Parent(01,02);
em.persist(p);
Child c = new Child(02,"bob");
em.persist(c);
p.children = Collections.singleton(c); // connect the child to the parent
em.getTransaction().commit();
After running the test with these fixes an ObjectDB database is created with the relationship.