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 Help in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help in HQL" Watch "Help in HQL" New topic

Help in HQL

Anurag Agarwal

Joined: Mar 07, 2009
Posts: 1

I am having difficulty creating an HQL statement. The following code is working

ICriteria criteria = session.CreateCriteria(typeof
criteria.CreateAlias("Addresses", "alist");
criteria.CreateAlias("alist.items", "add");
criteria.Add(Expression.Like("add.State", "U%"));
return criteria.List<Organization>();

but when I want to code the same in HQL I get an error "could not
resolve property: items of:". The hql is given below

string sql = "from Organization as o join fetch
o.Addresses a join fetch a.items x where x.State like 'U%'";
IQuery query = session.CreateQuery(sql);
return query.List<Organization>();

The mapping I am using is as follows

<class name="Organization" table="Organization" lazy="false">
<id name="OrganizationID" column="OrganizationID" type="int">
<generator class="native"/>
<property name="OrganizationName" column="OrganizationName"
type="String" not-null="true"></property>
<component name="Addresses">
<bag name="items" table="OrgAddressMap" lazy="false" cascade
="save-update" access="field">
<key column="OrganizationID"/>
<many-to-many class="Address" column="AddressID"/>

What is wrong with the HQL statement?


I agree. Here's the link:
subject: Help in HQL
It's not a secret anymore!