This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes max function showing error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "max function showing error " Watch "max function showing error " New topic

max function showing error

Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 122
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(
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.QueryImpl.list(
at FromClauseEx.main(

The class containing hql query--

public class FromClauseEx {
public static void main(String[] s){
Session sess=null;
SessionFactory sessFact = new Configuration().configure().
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---

<class name="Product" table="products">

<id name="productId" column="pid" />
<property name="proName" column="pname" length="10"/>
<property name="price" column="price" />


And the table name is "products"
it contains column pid,pname,price

please help me to solve this problem
Matthew Brown

Joined: Apr 06, 2010
Posts: 4342

That sounds like the query isn't finding any Products, so it's trying to find the maximum of no values, which is invalid. Are you sure there are Products in the database? Try running a query to count the Products instead of find the maximum price, to check.
Abhra Kar
Ranch Hand

Joined: May 22, 2008
Posts: 122
Hi I have change the query from String sql_query = "select max(price) from Product products"; to String sql_query = "select count(*) from Product products";
it find 4 rows

output --------------

Hibernate: select count(*) as col_0_0_ from products product0_
max investment amount --

The products table conains 4 rows

| pid | pname | price |
| 104 | HDD | 5000 |
| 106 | Mouse | 500 |
| 101 | HDD | 4000 |
| 102 | HDD | 4500 |
jQuery in Action, 2nd edition
subject: max function showing error
Similar Threads
Problem with Hibernate test application
How to return class instance?
Application logic & servlets
Null Pointer exception thrown while deploying the cmp bean
shopping cart problem