0
Friends, good afternoon.
I have a table in the database called Question Inside the table I have two columns that are code (id) and question. I have a filter that I can not specifically bring only code and ask because the return of the method is an object. I can only return the entire object.
How do I return only the code and the question table question?
It’s like I’m gonna make a:
select codigo, pergunta from Questao where curso_codigo = ?1 and complexidade = ?2;
Can someone help me?
Follows the method:
@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;
}
Cara retrieves the entire object then iterates and removes only the code and asks it... You generated toString(); in the Questao class?
– Wellington Avelino
I think that this is not a good alternative, both in terms of processing and memory consumption, there is no need to load more data than it will need the database, up to why, the entity
Questao
can be great.– Ricardo Rodrigues de Faria