asolfre / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

@Load Ref<Foo> fooRef - fooRef.get() returns null when Foo has parent #164

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
class Bar
 @Load Ref<Foo> fooRef;
 ...

class Foo
 @Parent Ref<Bar> barRef;
 ...

fooRef.get()returns null. Remove parent from Foo and it loads.

What is the expected output? What do you see instead?
instance of foo

What version of the product are you using? On what operating system?
4.0rc1

Please provide any additional information below.

Original issue reported on code.google.com by jens.sch...@gmail.com on 21 Jun 2013 at 12:32

GoogleCodeExporter commented 9 years ago
Did you save the field as non-parent, then are trying to change the field to 
@Parent and load it?

You can't do that. @Parent is part of the identity of an entity; changing the 
@Parent references a new and different entity. Read this:

https://code.google.com/p/objectify-appengine/wiki/Concepts#Keys

Closing as Invalid. If I have misunderstood the issue, please clarify and I 
will reopen. If you would like to start a discussion, please use the Google 
Group (linked at the google code home page for Objectify).

Original comment by lhori...@gmail.com on 21 Jun 2013 at 2:01

GoogleCodeExporter commented 9 years ago
No that is not the problem. I do not use old data. Let me be more clear:

fooRef.get()returns null when Foo has a @Parent attribute (and a parent). But 
then perform the same test… from scratch with new data (without a parent) and 
you get the foo instance.

It looks like this is the same problem:
http://stackoverflow.com/questions/12951766/ref-get-does-not-work-if-comes-from-
a-just-loaded-listref

Original comment by jens.sch...@gmail.com on 24 Jun 2013 at 10:14

GoogleCodeExporter commented 9 years ago
I ran across this report while trying to debug similar symptoms. If anyone else 
reads this post, the following may be helpful.

Symptoms: class A holds a reference to class B and class B has a parent of 
class A. When I removed the @Parent from the parent key field in class B, the 
reference would return the correct value. Otherwise, it would return null.

Problem: I had created the reference using a manual key. That key did not 
consider the parent relationship.

It working when I removed the @Parent was a red herring

Solution: I just generated the reference with Ref.create( instanceOfObject )

Original comment by ste...@lightningrodgames.com on 5 Oct 2013 at 9:13