0
votes

for a project i'm making, i'm using Objectify and Google AppEngine

I'm quoting and old message from Google Groups, but the problem i have is the same:

Here's the problem I'm trying to solve: I'd like to persist instances of several subclasses of one superclass to the datastore, and then retrieve them by querying for that superclass.

(For example, a query for Game would return instances of Chess and Backgammon).

Is there any way to accomplish this using Objectify?

Because the thing i want is the same, but the topic does not provides yet an answer (it's 3 years old), I moved here with the same question.

As configuration, I've used polymorphism on Objectify. I have a class "Game" annotated with "@Entity" and 2 classes ("Chess" and "Backgammon"), that extends Game, annotated with "@Subclass".

If i query on "Game", i get 2 Game instances. But i want to get Chess and Backgammon instances

From 2010 to now, this question has been solved?

Thanks Bye

2

2 Answers

1
votes

If you used objectify's polymorphism, then is't simple: just query for the parent class.

Note: polymorhism in objectify is achieved by adding special hidden fields (^d and ^i) to the entity that mark the type of the subclass. So all objects with the same parent class will have the same entity kind (defined by @Entity on the parent class).

0
votes

That google group link is ancient and predates the implementation of polymorphism in Objectify. Yes, Objectify (for a very long time now) supports polymorphism with the @EntitySubclass annotation.

Peter's answer is correct. If you aren't seeing expected behavior, then you are doing something wrong and need to either elaborate in much more detail in the question or (better) post to the objectify google group.