2013-12-09 62 views
0

這是我的問題。Grails 2.2.2沒有爲參數2指定值

我有3個結構域類

Contributor.groovy

class Contributor extends User{ 
    static hasMany = [instruments:Instrument] 
} 

Project.groovy

class Project { 
    static hasMany = [instruments: Instrument] 
    static belongsTo = [contributor: Contributor] 
} 

Instrument.groovy

class Instrument { 
    static belongsTo = [Contributor, Project] 
    static hasMany = [projects: Project, contributors: Contributor] 
} 

然後,我有一個服務用一個函數來查找包含樂器的列表中的所有項目

def getProjectsByInstruments(){ 
     def result = null 
     def instrument = Instrument.findByName("Accordion"); 
     def instrumentList = new HashSet<Instrument>(); 
     instrumentList.add(instrument) 
     result = Project.findByInstruments(instrumentList) 
     return result 
} 

當我執行我收到此錯誤信息的功能:

2013-12-09 11:45:44,711 [http-bio-8081-exec-7] INFO soundshare.ProjectController - Entering Action /project/by_instrument 
2013-12-09 11:45:44,712 [http-bio-8081-exec-7] INFO soundshare.ProjectController - Instrument : ACCORDION 
2013-12-09 11:45:44,714 [http-bio-8081-exec-7] DEBUG hibernate.SQL - select this_.id as id17_0_, this_.version as version17_0_, this_.name as name17_0_ from instrument this_ where this_.name=? limit ? 
Hibernate: select this_.id as id17_0_, this_.version as version17_0_, this_.name as name17_0_ from instrument this_ where this_.name=? limit ? 
2013-12-09 11:45:44,717 [http-bio-8081-exec-7] TRACE sql.BasicBinder - binding parameter [1] as [VARCHAR] - Accordion 
2013-12-09 11:45:44,717 [http-bio-8081-exec-7] TRACE sql.BasicExtractor - found [1] as column [id17_0_] 
2013-12-09 11:45:44,727 [http-bio-8081-exec-7] TRACE sql.BasicExtractor - found [1] as column [version17_0_] 
2013-12-09 11:45:44,727 [http-bio-8081-exec-7] TRACE sql.BasicExtractor - found [Accordion] as column [name17_0_] 
2013-12-09 11:45:44,729 [http-bio-8081-exec-7] DEBUG hibernate.SQL - select this_.id as id31_0_, this_.version as version31_0_, this_.contributor_id as contribu3_31_0_, this_.description as descript4_31_0_, this_.musical_style_id as musical5_31_0_, this_.name as name31_0_, this_.open_to_public as open7_31_0_, this_.poster_url as poster8_31_0_ from project this_ where this_.id=? limit ? 
Hibernate: select this_.id as id31_0_, this_.version as version31_0_, this_.contributor_id as contribu3_31_0_, this_.description as descript4_31_0_, this_.musical_style_id as musical5_31_0_, this_.name as name31_0_, this_.open_to_public as open7_31_0_, this_.poster_url as poster8_31_0_ from project this_ where this_.id=? limit ? 
| Error 2013-12-09 11:45:44,729 [http-bio-8081-exec-7] ERROR util.JDBCExceptionReporter - No value specified for parameter 2 
| Error 2013-12-09 11:45:44,742 [http-bio-8081-exec-7] ERROR errors.GrailsExceptionResolver - SQLException occurred when processing request: [POST] /project/by_instrument - parameters: 
instrument: accordion 
No value specified for parameter 2. Stacktrace follows: 
Message: No value specified for parameter 2 

感謝您的幫助

+0

張貼整個堆棧跟蹤它會很容易找到剛纔編輯我的職務與全堆棧跟蹤 – Deepak

+0

:Project.findByInstruments(instrumentList ),因爲我不相信它。 – Merlin

+0

我令人頭大我的大腦試圖記住如何,這是一個有效的動態取景器的問題 – Gregg

回答

1

嘗試此查詢

Project .withCriteria { 
    instruments{ 
    eq('name', 'Accordion') 
    } 
} 
+1

您的解決方案有效,您能解釋爲什麼我的不?無論如何感謝 – Merlin

+0

嘗試此操作後,我的錯誤現在顯示爲:「沒有爲參數1指定值」。有人可以解釋這個錯誤,以及它應該如何解決? – Weezle

相關問題