I'm following the ZenTask application for the play-framework tutorial and I currently ended up here: http://www.playframework.com/documentation/2.2.x/JavaGuide3
Now I think I have either found a bug or I'm missing something in my reasoning, anyway, the tutorial has the following line of code in Application.java
:
Task.find.all()
The Task class has two interesting fields:
@ManyToOne
public User assignedTo;
@ManyToOne
public Project project;
Now I have the following test cases:
@Test
public void successUserLoadTest(){
List<Task> tasks = Task.find.all();
for(Task t : tasks){
if(t.assignedTo != null)
assertNotNull(t.assignedTo.name);
}
}
@Test
public void failingProjectLoadTest(){
List<Task> tasks = Task.find.all();
for(Task t : tasks){
if(t.project != null)
assertNotNull(t.project.name);
}
}
@Test
public void successProjectLoadTest(){
List<Task> tasks = Task.find.fetch("project").findList();
for(Task t : tasks){
if(t.project != null)
assertNotNull(t.project.name);
}
}
The problem is that the project field is not populated/loaded while the assignedTo field is. And when I explicitly load the project field there is no problem.
Any idea's how I can solve this or is it better practice to explicitly load all ManyToOne
fields?
Greetings!