I began having sporadic problems in my Play Framework 2.0.4 application where the attributes of referenced objects were null.
When getting a Contact object with ebean:
Contact contact = Contact.find.byId(id)
will be null.
However, this will return the correct value:
So I started googleing the problem and found this:
Enhancement of direct Ebean field access (enabling lazy loading) is only applied to Java classes, not to Scala. Thus, direct field access from Scala source files (including standard Play 2 templates) does not invoke lazy loading, often resulting in empty (unpopulated) entity fields. To ensure the fields get populated, either (angel) manually create getter/setters and call them instead, or (beer) ensure the entity is fully populated before accessing the fields.
This described the problem but offered a poor solution…
Then I found this thread with the answer: http://stackoverflow.com/questions/12977513/ewonetoone-relationship-with-play-framework-that-does-not-use-join
When loading the contact, you have to force the loading of the user as well!
If you have read this far, you may as well follow me on Twitter:
Contact contact =