Hi,
I have two tables that share the same heading_key column. I am using the following statement using criteria to retrieve the headingcode:
org.hibernate.Criteria criteria = getPersistenceEngine() .getPersistenceSession().getHibernateSession() .createCriteria(Heading.class, "h") .createCriteria("customer", "c");
criteria.setFetchMode("customer", FetchMode.JOIN) .add(Restrictions.eq("h.headingKey", "c.headingKey" )) .add(Restrictions.eq("c.customerId", Long.parseLong(customerId))) .setProjection(Projections.distinct(Projections.projectionList() .add(Projections.property("h.headingCode").as(headingCode"))));
list = criteria.list();
my xml files are defined:
customer:
<hibernate-mapping> <class table="customer" name="com....domain.Customer"> <id name="headingKey" column="heading_key" type="long" unsaved-value="null" > <generator class="native"> </generator> </id> <property name="customerId" not-null="false" type="long" column="customer_id" /> Heading: <hibernate-mapping> <class table="heading" name="com....domain.Heading"> <id name="headingKey" column="heading_key" type="long" unsaved-value="null" > <generator class="native"> </generator> </id> <property name="headingCode" not-null="false" type="java.lang.String" column="heading_code" /> <set name="customer" > <key column="heading_key"/> <one-to-many class="com....domain.Customer" /> </set>
The query I get from hibernate is:
select distinct this_.heading_code as y0_ from heading this_, customer c1_ where this_.heading_key=c1_.heading_key and this_.heading_key=? and c1_.customer_id=?
Which is what I want minus the second to the last line. What I am doing wrong?
Thanks for your help.
|