robinbuehler robinbuehler - 1 year ago 143
Java Question

Objectify 5 - filter embedded entity field doesn't work

I try to load a list of objects from my own class called 'Payment'. Now I do not want to load all payments but only those who have a specific 'Group' as parent (Group is also an own class).

This is the Payment class:

public class Payment {
@Id private Long id;
@Index @Load private Ref<Group> parent;
// other fields, constructors, getters and setters

And this is my Group class:

public class Group {
@Index @Id private Long id;
// other fields, constructors, getters and setters

The following is the method in which I try to load this list of payments:

public static List<Payment> getPaymentsByGroup(Group group) {
List<Payment> payments = ofy().load().type(Payment.class)
.filter("", group.getId()).list();
return payments;

But the result is always an empty list. But if I try to do something like this:

public static List<Payment> getPaymentsByGroup(Group group) {
List<Payment> temp = new ArrayList<>();
List<Payment> payments = ofy().load().type(Payment.class).list();
for (Payment payment : payments) {
return temp;

I'll get my payments. I use Objectify 5. Because of the performance, the Payment class should be an own Entity and not be stored as a normal embedded object in the Group class. Otherwise the whole group object would have to be stored with all payments by adding one single payment.

What am I doing wrong? How can I filter a field in an embedded entity?

Answer Source

I think you might be confusing terminology here as I don't see a @Parent (entity group) or an embedded entity. I do see a Ref<?>, which is essentially a Key.

If you change your query to

List<Payment> payments = ofy().load().type(Payment.class).filter("parent = ", Ref.create(group)).list();

it should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download