| 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
|
 |
 |
|
|
subject: size() collection not working in HQL
|
|
|