Two Laptop Bag
The moose likes Object Relational Mapping and the fly likes size() collection not working in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply 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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: size() collection not working in HQL
 
Similar Threads
null pointer exception
Joins using Hiberntes
ClassCastException Hibernate
one to one mapping problem
inner join not working !!! please help