Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Projecting subclass properties fails #317

@danrods

Description

@danrods

Assuming the following structures

@Entity
public class Foo{
  @Id Long id;
   @Index private int number;
}

@Subclass(index=true)
public class Bar extends Foo{
   @Index int numberTwo;
   @Index String someval;
}

Attempting to project has some weird behavior.

ofy.load().type(Foo.class).project("numberTwo").filter("someval", "foobar").first().now();

Running the above query will return me an object of type "Foo" with all of the foo properties filled in, and none of the bar properties, especially the property I projected.

ofy.load().type(Bar.class).project("numberTwo").filter("someval", "foobar").first().now();

Will throw a class cast exception trying to convert Foo to Bar.

It seems to me like Objectify will only load properties for the top level Entity and none of the sub-classes when projecting and will completely ignore the type parameter and any properties of classes in the ^i or ^d properties.

I searched all over and can't seem to find a reason for this in Datastore or the ofy documentation so I'm going to assume it might not be desired behavior.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions