문제

I am starting to learn Play Framework 2, and have met a strange problem.

I have a OneToMany relationship defined between a Project and its many Tasks.

@Entity
public class Project extends Model {
    @OneToMany(mappedBy="project", cascade=CascadeType.ALL)
    public List<Task> tasks = new ArrayList<Task>();
}

@Entity
public class Task extends Model {
    @ManyToOne
    public Project project;
}

I have some code that finds and displays a Project :

final Project foundProject = Project.find(id);
//Logger.error("Tasks size:"+foundProject.tasks.size());
return ok(views.html.tasks.render(foundProject, taskForm));

And a view:

@for(task <- project.tasks) {
    <li>@task.title</li>
}

Note the commented-out Logger line in the code that finds the Project. If that line is commented out, then no Tasks are shown, if the line is NOT commented out, then Tasks are shown.

It's as if some kind of lazy initialisation code works inside the Controller but not inside the View. Is there a subtlety of Play that I have missed, or am I doing something wrong?

도움이 되었습니까?

해결책

It was my fault - I'm new to eBean and was doing this in the code to find my project:

finder.ref(id);

instead of:

finder.byId(id);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top