In a Google App Engine app, I have this model:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Message {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private Date timestamp;
@Persistent
private String text;
@Unowned
@Persistent(defaultFetchGroup = "true")
private User sender;
...
}
The model has an @Unowned
relation to a sender, since a user can exist independently of a message.
What I want to do is persist Message
objects with partial User
objects (e.g. I'm only interested in storing the user id and username). In my endpoint class I'm storing messages just fine, however, if I don't include all fields for the given user in the relationship, the user object is updated with the fields missing (e.g. user in question no longer has a password etc.). What is the best way of achieving what I want, without 'corrupting' the original object?
PS
My endpoints method is dead simple. Basically just calling pm.makePersistent(message);
on the message (given as a method parameter).