Hibernate version: 3.0
Hello guys,
I'm having a difficult to write a specific HQL. Here's what I want:
I have a table MATERIAL_QTT with the following fields: date, material, color, quantity
And a table MATERIAL with: material, desc, minQuantity.
I wanna select from the material_qtt all the materials which have the quantity less than the specified in material.minQuantity. So far so good. The problem is that I have tuples in material_qtt with same material and color, only different date. Like this:
--> Date = 05/05/2005, Material = "MA", Color = "Red", Quantity= 10
--> Date = 05/07/2005, Material = "MA", Color = "Red", Quantity= 11
And I wanna select only the one with the date closer to the actual date.
Here's what I'm doing:
Code:
Query select = session.createQuery("from EstoqueMP e where " +
" e.qtde < e.materia.estoqueMinimo " +
" and e.data = (select max(data) from EstoqueMP e1" +
" where e1.materia = e.materia" +
" and e1.cor = e.cor)" );
But I'm getting the error:
Code:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.AggregateNode
\-[AGGREGATE] AggregateNode: 'max'
\-[IDENT] IdentNode: 'data' {originalText=data}
So I suppose max isn't the correct way to do it.
Any help? thanks