1
我有這樣的領域中的Grails:我如何在Grails的/格姆/休眠執行specifc SQL
class Questao {
static transients = [ "tags" ]
String enunciado
Double valorQuestao
byte[] imagem
public enum Tipo {
ALTERNATIVAS,
VF,
SUBJETIVA
}
Tipo tipoQuestao
static hasMany = [alternativas:Alternativas, assuntos: QuestaoAssunto, provas: Prova]
static belongsTo = [Prova]
static mapping = { enunciado type: 'text'}
static constraints = {
imagem nullable: true, maxSize: 160384
alternativas nullable: true
}
}
class QuestaoAssunto {
Questao questao
Assunto assunto
static belongsTo = [Questao,Assunto]
}
class Assunto {
String titulo
static hasMany = [questoes:QuestaoAssunto]
static belongsTo = [Questao]
}
,我需要執行這個SQL:
select q.* from questao_assunto qa join questao q on q.id=qa.questao_id where assunto_id in (:assuntos_id) and q.tipo_questao = 'SUBJETIVA' GROUP BY q.id order by rand() limit 1;
:assuntos_id是陣列像[5,6]
怎麼能這樣?