I need to apply a SQL Query similiar to this.
SELECT
id as id,
c03 as c03,
c34 as c34
FROM
(SELECT
id,
c03,
c34
FROM
students
where
c34 in(
?, ?,?,?
)
order by
id desc) o
group by
c34;
And My Java code.
private final void retrieveStudents(){
final List result = currentSession()
.createSQLQuery("SELECT id as id,c03 as c03,c34 as c34 FROM (SELECT id,c34,c03 FROM students where c34 in(:filters) order by id desc) o group by c34;")
.setParameterList("filters",Arrays.asList(74,1812))
.list();
result.forEach(this::consumer1);
}
The query is Just OK. Returns a array of objets which i can iterate but i would like to return a Student object so i add.
.addEntity(Student.class)
But a error is throw which says
Column 'ACTIVE' not found.
Also i have try with .addScalar but the same thing happens.
.addScalar("id",org.hibernate.type.IntegerType.INSTANCE)
.addScalar("c03",org.hibernate.type.DateType.INSTANCE)
Which is a column from Student but is not on the projection my question how can i do that i just thought that applying in some way the alias would Hibernate populate the student entity.
All i want is a Student object with id,c03,c34 values populate.
What i am doing wrong is that possible?