Play Framework通用方法让我头疼

时间:2012-02-25 18:34:58

标签: java playframework

我在目录模型中使用此方法:

public List<Directory> subdirectories() {
    return find("select d from Directory d where d.parent = ?", this.id).fetch()
}

这个测试:

@Test
public void testSubdirectories() {
    Directory d1 = Directory.find("byName", "d1").first();
    Directory d2 = Directory.find("byName", "d2").first();
    Directory d3 = Directory.find("byName", "d3").first();
    Directory d4 = Directory.find("byName", "d4").first();

    List<Directory> d1subs = d1.subdirectories();
    List<Directory> d2subs = d2.subdirectories();
    List<Directory> d3subs = d3.subdirectories();
    List<Directory> d4subs = d4.subdirectories();

    assertTrue(d1subs.contains(d2));
    assertTrue(d1subs.contains(d3));
    assertTrue(d2subs.isEmpty());
    assertFalse(d1subs.contains(d4));
    assertTrue(d3subs.contains(d4));
    assertTrue(d4subs.isEmpty());
}

这个类型检查,但是当我运行测试时,我收到以下错误:

A java.lang.IllegalArgumentException has been caught, Parameter value [5] was not matching type [models.Directory]
In /test/models/DirectoryTest.java, line 37 :
List<Directory> d1subs = d1.subdirectories();

任何人都可以解释问题是什么,以及如何解决它?

1 个答案:

答案 0 :(得分:3)

不应该是

return find("select d from Directory d where d.parent.id = ?", this.id).fetch();

或其缩短版应为

return find("parent.id = ?", this.id).fetch();