Ich habe Domains wie in Grails:Wie kann ich eine specifc SQL in Grails/GORM/Hibernate ausführen
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]
}
und ich brauche diese SQL auszuführen:
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 eine ist Array wie [5,6]
wie kann man das machen ??