1

我有一个培训领域课程

    class Training {

     String type
     Date createdOn
     Date modifiedOn

    static belongsTo = [course: Course]
    static hasMany = [attachments: Attachment]
  }

我有课程领域课程

     class Course {

          String name

          static hasMany = [trainings: Training, tracks: Track]
          static belongsTo = Track
   }

和跟踪域类

    class Track {
        String name 
    }

我想根据轨道选择培训。

现在说我得到了track id,我想根据Track id检索训练

我试过这样的查询

 def query = "FROM Training AS t WHERE  t.course.tracks.id IN (1,2)"
  trainingList = Training.findAll(query)

它给

 illegal attempt to dereference collection

错误..因为我做不到t.course.tracks.id

如果我有跟踪 ID(比如 1、2),请帮助我编写正确的 hql 查询以获得培训

4

2 回答 2

0

你能做的就是这个

def query = "FROM Training AS t join t.course as c join c.tracks as tr WHERE  tr.id IN (1,2)"
trainingList = Training.findAll(query)

问题是当您尝试从一个到多个时。

于 2013-08-22T00:21:47.523 回答
-1

Please find below the HQL to retrieve all the trainings for tracid 1 & 2.

from Course c, Track tr, Training t where tr.courceid= c.courceid and tr.trackid=c.tracid and tr.trackid in (1,2)

于 2012-09-13T13:18:18.060 回答