Hi,
I am trying to execute 'max' function in hql but getting error--
Exception in thread "main" java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.AggregateNode
\-[AGGREGATE] AggregateNode: 'max'
\-[ALIAS_REF] IdentNode: 'price' {alias=price, no from element}
at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:122)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:414)
......................................................
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at FromClauseEx.main(FromClauseEx.java:21)
The class containing hql query--
public class FromClauseEx {
public static void main(String[] s){
Session sess=null;
SessionFactory sessFact = new Configuration().configure().
buildSessionFactory();
sess= sessFact.openSession();
String sql_query = "select max(price) from Product products";
Query query = ses.createQuery(sql_query);
List list = query.list();
System.out.println("max investment amount --" +list.get(0));
}
}
The Product class----
public class Product{
private int productId;
private String proName;
private int price;
public void setProductId(int productId)
{
this.productId = productId;
}
public int getProductId()
{
return productId;
}
public void setProName(String proName)
{
this.proName = proName;
}
public String getProName()
{
return proName;
}
public void setPrice(int price)
{
this.price = price;
}
public int getPrice()
{
return price;
}
}
The Product.hbm.xml---
<hibernate-mapping>
<class name="Product" table="products">
<id name="productId" column="pid" />
<property name="proName" column="pname" length="10"/>
<property name="price" column="price" />
</class>
</hibernate-mapping>
And the table name is "products"
it contains column pid,pname,price
please help me to solve this problem
Thanks