문제

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!

도움이 되었습니까?

해결책

Upgrading to play-2.2.2-RC2 seems to have solved to problem. A similar problem is described here: Play 2.1.3 application with Maven enhanced models not loading lazy objects

Still no explanation why the assignedTo field was populated, a bug is most likely in this case.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top