So I am not having any luck with loading the venue and artist object when I load my even object. Basically when I create an event, I load the specific artist and specific venue and save the key in the event's artistKey and venueKey fields. However, when I load even it is always null. I have tried annotations "@Persistent(defaultFetchGroup = "true")" and also "@Persistent(mappedBy = "venue") @Element(dependent = "true")" on my venue and artist with no luck as artist/venue still come up as null when I load an event (the keys are there). When I try the defaultFetchGroup it says I cannot load a parent if it has already been persisted, which make sense I guess.
public class Event {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private Key artistKey;
@Persistent
private Key venueKey;
private Artist artist;
private Venue venue;
//other fields
//getters and setters
}
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Venue {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
//other fields
//getters and setters
}
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Artist {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
//other fields
//getters and setters
}
with relations (in GAE) you have to pay attention to whether they are owned (stored with the owning object in the datastore) or unowned (like they are in all other datastores). You can mark relations as @Unowned if the latter. GAE has some restrictions around entity groups that impact on this - see their docs