How do I not update the embedded object?

0 views
Skip to first unread message

Johnny Wu via StackOverflow

unread,
Dec 8, 2015, 10:43:04 PM12/8/15
to google-appengin...@googlegroups.com

I have two entities: entity A and entity B.

Entity A has entity B as a reference (Ref).

The issue is that when I retrieve entity A I want it to carry over entity B, but when I update entity A, I don't want to update entity B.

Is this even possible with Objectify or do I need to re-design?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/34170260/how-do-i-not-update-the-embedded-object

Mohamed Seif via StackOverflow

unread,
Dec 8, 2015, 11:08:04 PM12/8/15
to google-appengin...@googlegroups.com

unfortunately Java is always pass by reference, means that any Object A = B, than you try to change B, A will change too, the only way to do this is to create new Object A = new Object(); then you copy the contents of Object B to Object A, will be something like this

int someInt = 5;
Object B = new Object(someInt);

where the constructor of class Object taking "someInt" Parameter.

class Object {
int j;
 Object(Int i)
{
 this.j=i;
}
int getInt() 
{
  return j;
 }

then you create A and equalize the content of A to the Content of B

  Object A = new Object(B.getInt());


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/34170260/how-do-i-not-update-the-embedded-object/34170528#34170528
Reply all
Reply to author
Forward
0 new messages