How to eager load a collection in ebean?
Asked Answered
K

1

6

What is the correct way to eager fetch a nested collection in ebean and Play Framework 2? I tried this:

Registration registration = find
    .fetch("participants")
    .fetch("participants.fieldValues")
    .fetch("participants.fieldValues.field")
    .where().eq("token", token).findUnique();

For some reason registration.participants.fieldValues.field objects only have an id. The rest of the field properties are null. E.g. field.name is null when it should have a value.

Edit: If I make Field.name private and add a getter/setter for it, then I can get its value. But since I'm using fetch("participants.fieldValues.field") shouldn't that make it eager fetch without needing the getter/setter?

Kaja answered 20/1, 2013 at 17:53 Comment(3)
Faced the issue many times, now I'm using getters and setters :-(Glick
Here's this great new framework. It generates getters and setters for you so you save time and keep your code clean. Now the first thing you need to do to access your data is write getters and setters. WTF?Kaja
Please post the sample as git repo. I am curious about this too. Then we will ask this in the google group or post a bug report.Glick
Y
4

Magic that does not work is a waste of time for everybody. I have had numerous issues with genrated getters and setters. Some also related to referencing models in templates. I created getters and setters and kept fields private for my ebean models and never looked back.

Yellowhammer answered 27/2, 2013 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.