File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes size() collection not working in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "size() collection not working in HQL" Watch "size() collection not working in HQL" New topic

size() collection not working in HQL

subhasish sahu

Joined: Nov 27, 2009
Posts: 3
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<class name="contact.Insurance" table="InsuranceDetails">
<id name="id">
<generator class="assigned"/>
<property name="name">
<column name="insurance_name"/>

<property name="amt">
<column name="invested_amount"/>


package contact;
public class Insurance
private int id;
private String name;
private int amt;

public Insurance(){}

public void setId(int id)
{ = id;
public void setName(String name)
{ = name;
public void setAmt(int amt)
this.amt = amt;
public int getId()
public String getName()
public int getAmt()
return this.amt;


package contact;
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;

public class FromClauseDemo
public static void main(String args[])
Session session = null;
SessionFactory factory = null;

factory = new Configuration().configure().buildSessionFactory();
session = factory.openSession();
String sql = "select,,ins.amt from Insurance ins where size(ins.amt) >=2";
Query q = session.createQuery(sql);
List l = q.list();
Iterator i = l.iterator();

catch(Exception e)

static void Display(Iterator i)
Object []o = (Object[]);
System.out.print("\t" +o[1]);
System.out.println("\t" +o[2]);

[java] org.hibernate.QueryException: could not resolve property: size of: c
ontact.Insurance [select,,ins.amt from contact.Insurance ins wher
e size(ins.amt) >=2]

size not working .......please help ??
akhtar qureshi

Joined: Nov 24, 2009
Posts: 16
SQL query not support size function. you use lenght function and its aggregation function use before from clause
I agree. Here's the link:
subject: size() collection not working in HQL
It's not a secret anymore!