Grails中的HQL连接
我试图执行查询以收集特定数据,但在查询的Grails中的HQL连接,grails,hql,Grails,Hql,我试图执行查询以收集特定数据,但在查询的on部分遇到问题。首先,这是我的课程: class TimeSlot { String timeslot_id String time_chunk_id String uid String exam_id String start_time String is_special_arrangement static mapping = { table 'timeslot'
on
部分遇到问题。首先,这是我的课程:
class TimeSlot {
String timeslot_id
String time_chunk_id
String uid
String exam_id
String start_time
String is_special_arrangement
static mapping = {
table 'timeslot'
id name: "timeslot_id", column: "timeslot_id"
version false
}
}
这是我正在尝试的查询:
TimeSlot.executeQuery("Select t.time_chunk_id, t.uid, t.start_time, t.timeslot_id, t.is_special_arrangement, e.length from TimeSlot t inner join Exams e on t.exam_id = e.exam_id where t.exam_id = ? and t.time_chunk_id = ?", [testArray[i], timeChunkArray[x]])
它在部分的
上抛出了一个错误,因为它需要一个子句,但我需要与两个表的exam.id
比较相关的数据。是否有其他方法或其他不同的方法来设置查询,使其能够像在任何SQL编辑器中一样工作?如果更改域类并添加一对多关系,会更容易
class TimeSlot {
static hasMany = [examinations:Exams]
那么HQL可以是
select ... from TimeSlot t join t.examinations e
在查询中,将与
一起使用,而不是在
上使用。HQL不支持关键字上的。它的等价物是with
。这消除了错误,但现在它说in不能解析t处的符号t
。对发生这种情况的原因有什么建议吗?使用时间段中的作为T,考试作为e,其中T.exam\u id=e.exam\u id
。我尝试不将其拆分为两个不同的查询,因为它不会产生与我当前尝试使用的特定查询相关的相同结果。如果您还不知道,您可以将域对象映射到exam\u id
列。类似于考试列:考试id
在时间段内考试所在的位置考试