I have a question about child - parent entities relationship in the
context of Objectify4.
So in Ofy3 in parent class I used to have @Transient field for
GWT RPC with child and Key<> field that actually goes to Datastore.
My understanding was that Ofy4 has simplified it and there is no
more need for two fields per relationship.
Here is my child
@Entity
public class Person extends DatastoreObject
{
@Index
private String name;
@Index
private String phoneNumber;
@Index
private String email;
@Parent
private Organization organization;
}
but I'm not sure what I should do in parent.
@Entity
public class Organization extends DatastoreObject
{
@Index
private String name;
@Index
private String address;
@Index
private Person contactPerson; // like this ? seems unlikely
}
My understanding is that I should persist Organization first so I
can persist Person which needs valid key of its parent.
But I can't serialize Organization because Obf says there is field
with null-key (which is true).
I tried to mark Organization.contactPerson as @Ignore. I serialize
it but then I can't serialize Person because Objectify says I can't
persist entities from two different groups in one transaction. But
they are not in different entity groups. It's the same group, right?
/Ruslan
/K Vassiliadis ft Marien - Den Efiges Lepto (dub mix) (1.FM - The Chillout Lounge)
> Dear Objectify-appengine,
> I have a question about child - parent entities relationship in the
> context of Objectify4.
Just to clarify my question I want to say that I don't understand
use-case for @Load in parent class. I can imagine how it works on
fetching. Perhaps it's querying children with its own key. But I don't
understand how @Load on field in parent class would work when I
persist instance of parent class.
/Ruslan
/Leila Pantel - Energia (1.FM - The Chillout Lounge)
My understanding was that Ofy4 has simplified it and there is no
more need for two fields per relationship.
Here is my child
but I'm not sure what I should do in parent.
My understanding is that I should persist Organization first so I
can persist Person which needs valid key of its parent.
But I can't serialize Organization because Obf says there is field
with null-key (which is true).
I tried to mark Organization.contactPerson as @Ignore. I serialize
it but then I can't serialize Person because Objectify says I can't
persist entities from two different groups in one transaction. But
they are not in different entity groups. It's the same group, right?
Thursday, February 23, 2012, 11:42:31 PM, you wrote:Just to clarify my question I want to say that I don't understand
> Dear Objectify-appengine,
> I have a question about child - parent entities relationship in the
> context of Objectify4.
use-case for @Load in parent class. I can imagine how it works on
fetching. Perhaps it's querying children with its own key. But I don't
understand how @Load on field in parent class would work when I
persist instance of parent class.
| Are you expecting Objectify to maintain both ends of a bidirectional relationship for you, the way that JDO and JPA do? |
| Objectify doesn't do that. It's very much what-you-see-is-what's-in-the-datastore, but just smart enough to translate an entity reference into a key reference for you. If you never set Organization.contactPerson to a value, it will be null. |
| If I've misunderstood your code... can you post a complete test case that shows what you expect to happen? |