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?

TomahawkPhant
  • 1,130
  • 4
  • 15
  • 33
  • Faced the issue many times, now I'm using getters and setters :-( – adis Jan 21 '13 at 08:34
  • 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? – TomahawkPhant Jan 21 '13 at 17:51
  • 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. – adis Jan 21 '13 at 20:04

1 Answers1

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.

col
  • 397
  • 3
  • 10