This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

size() collection not working in HQL

subhasish sahu
Greenhorn

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

<property name="amt">
<column name="invested_amount"/>
</property>
</class>
</hibernate-mapping>




-------------------------------------------------------------------------------------------


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

public Insurance(){}

public void setId(int id)
{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
public void setAmt(int amt)
{
this.amt = amt;
}
public int getId()
{
return this.id;
}
public String getName()
{
return this.name;
}
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;

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



}
catch(Exception e)
{
System.out.println(e.toString());
}
}

static void Display(Iterator i)
{
while(i.hasNext())
{
Object []o = (Object[])i.next();
System.out.print(o[0]);
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.id,ins.name,ins.amt from contact.Insurance ins wher
e size(ins.amt) >=2]




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

Joined: Nov 24, 2009
Posts: 16
SQL query not support size function. you use lenght function and its aggregation function use before from clause
 
Don't get me started about those stupid light bulbs.
 
subject: size() collection not working in HQL