Friends, good afternoon.
I have a table in the database called Questao Inside the table I have two columns that are ID and Question . I have a filter that I can not specifically bring only code and asks because the method return is an object. I can only return the entire object.
How do I return only the code and question of the question table?
It's like I'm going to make one:
select codigo, pergunta from Questao where curso_codigo = ?1 and complexidade = ?2;
Can anyone help me?
The method follows:
@SuppressWarnings("unchecked")
public List<Questao> geraSimuladoPorFiltro(Long codigoCurso,
Integer complexidade, Integer numeroDeQuestoes) {
String query = "from Questao WHERE curso_codigo = ?1 AND complexidade = ?2";
List<Questao> questoes = manager.createQuery(query)
.setParameter(1, codigoCurso)
.setParameter(2, complexidade)
.setMaxResults(numeroDeQuestoes)
.getResultList();
for (Questao questao : questoes) {
System.out.println(questao.getCodigo());
System.out.println(questao.getPergunta());
}
return questoes;
}