0
votes

Initially my task was to filter the records by date for which I wrote the below query that returned no result even though I have 4 records in data store that meets the condition

    ObjectifyService.run(() -> ObjectifyService.ofy().cache(false).load().type(SomeClass.class).filter("createdDate <", date.toString())
                .list());

Note - I have the index for createdDate.

Later, Just wanted to check whether it is really fetching things, I wrote fetch all records which returns no results

    ObjectifyService.run(() -> ObjectifyService.ofy().cache(false).load().type(SomeClass.class).list());

I have a method that queries on id and right now only that works.

    ObjectifyService.run(() -> ObjectifyService.ofy().cache(false).load().type(SomeClass.class).id("someId").now());

Can't figure what's the issue here.

Below is the Entity itself

    @Entity(name = "SomeClass")
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Subclass
    public class SomeClass implements Serializable {

        @Id
        private String id;
        private int importId;
        private String name;
        private String value;
        private Date lastModified;
        @Index
        private Date createdDate;
        private List<SomeOtherClass> someOtherClass;

    }

I feel this has something to do with @subclass annotation. Is it so?

1

1 Answers

1
votes

Your problem is right here:

filter("createdDate <", date.toString())

You're filtering a date field by a string value. Date fields must be filtered by date values. Drop the toString() and you should see expected behavior.

The schemaless nature of the datastore means you don't get typechecking errors when comparing values of different types. In fact, you could save some entities with the field as String and some entities with the field as Date (generally though it's a bad idea). The datastore has an absolute ordering; all Strings (no matter their content) are larger than all Dates, so your filter returns nothing.