google Analytics

Monday, July 26, 2010

Hibernate List execute Associatons SQL

select column selection from different POJO

public void executeAssociationObjectsHQL(Session session)
{
String hql = "from Product p inner join p.supplier as s";
Query query = session.createQuery(hql);
List results = query.list();
displayObjectsList(results);
}


public void displayObjectsList(List list)
{
Iterator iter = list.iterator();
if (!iter.hasNext())
{
System.out.println("No objects to display.");
return;
}
while (iter.hasNext())
{
System.out.println("New object");
Object[] obj = (Object[]) iter.next();
for (int i=0;i {
System.out.println(obj[i]);
}


}
}

public void displayObjectList(List list)
{
Iterator iter = list.iterator();
if (!iter.hasNext())
{
System.out.println("No objects to display.");
return;
}
while (iter.hasNext())
{
Object obj = iter.next();
System.out.println(obj.getClass().getName());
System.out.println(obj);
}
}

No comments:

Post a Comment