I have an existing google app engine java application runs with jpa and now i am trying to move to objectify for many different purposes.
Current application has the below representation of the entities.
Class Parent{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
@OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
private List<Child> childs = null;
}
Class Child{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
@ManyToOne
private Parent parent;
}
How can i get the above representation in Objectify? I am using objectify4.
I have seen @Parent, but it seems not possible to load the list of child entities directly while fetching a parent?
Thanks,
Ramesh.V
Objectify uses different concepts than relational data stores and ORMs. Relations are constructed using Keys and are not loaded automatically. You can read about the modelling of relationships in Objectify here. The @Parent relationship is something special and is not the one relevant for 1:n or n:m relationships.
So basically you have
class Parent {
Key<Child>[] childs;
}
class Child {
Key<Parent> parent;
}
And then you would get the entities via the Objectfy service, e.g.
Parent aParent = ofy.get(aChild.parent);
There are no lazily loaded collections. If you want to construct a set of objects you need to do it explicitely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With