|
Hi everybody, I'm trying to model a one-to-one owned (one-direction) relationship, where the owned object (Stat) is created inside the owner (User). ----------------------------------- public class User implements IsSerializable { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") private String encodedKey; @Persistent private String userId; @Persistent private Stat stat= new Stat(); public User() {} public String getEncodedKey() { return this.encodedKey; } public void setEncodedKey(String encodedKey) { this.encodedKey = encodedKey; stat.setEncodedKey(KeyFactory.keyToString(KeyFactory.stringToKey(encodedKey).getChild(Stat.class.getSimpleName(), userId))); } public void setUserId(String userId) { this.userId = userId; stat.setUserId(userId); } public String getUserId() { return userId; } public void updateStat(long number) { stat.updateStat(number); } public Stat getStat() { return stat; } } ---------------------------- this implementation however produces a strange behaviour. Every time I try to access the User entity a new Stat object is created into the datastore: For example this call will create an object even if the user object doesn't exist: User user = pm.getObjectById(User.class, userEncodedKey); Am I using the one-to-one relationship in a wrong way??? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~----------~----~----~----~------~----~------~--~--- |
- [appengine-java] strange behavior of one-to-one owned (one-... Patrizio Munzi
- [appengine-java] Re: strange behavior of one-to-one ow... Ian Marshall
- [appengine-java] Re: strange behavior of one-to-on... Patrizio Munzi
