2012-02-25 68 views
2

我有一個目錄模型這種方法:遊戲框架的通用方法讓我頭疼

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()); 
} 

這typechecks,但是當我運行測試,我得到出現以下錯誤:

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(); 

任何人都可以解釋什麼是問題,以及如何解決它?

回答

3

不應該這個是

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

或相同的縮寫版本應該是

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

這是絕對正確的!我爲自己沒有找到它感到痛心。非常感謝,祝你有美好的一天! – gnuvince 2012-02-25 21:00:38

+1

總是樂於幫助 – Codemwnci 2012-02-25 21:50:05