【问题标题】:Grails 2.2.2 No value specified for parameter 2Grails 2.2.2没有为参数2指定值
【发布时间】:2013-12-09 09:32:24
【问题描述】:

这是我的问题。

我有 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

感谢您的帮助

【问题讨论】:

  • 贴出整个堆栈跟踪,很容易找到问题
  • 刚刚用完整的堆栈跟踪编辑了我的帖子
  • 我绞尽脑汁试图记住这是一个有效的动态查找器:Project.findByInstruments(instrumentList),因为我不相信它是。
  • 为什么不呢? `class Project hasMany = [仪器:仪器]``
  • 你能解释一下吗?谢谢

标签: hibernate grails


【解决方案1】:

试试这个查询

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

【讨论】:

  • 您的解决方案有效,您能解释一下为什么我的解决方案无效吗?还是谢谢
  • 尝试此操作后,我的错误现在显示为:“没有为参数 1 指定值”。有人可以解释一下这个错误以及应该如何解决它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-02
  • 2020-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多