Hi,
Supposed I Have 3 table , CUSTOMER , EVENT , CUSTOMER_EVENT
where CUSTOMER can participate in MANY EVENT
and ONE EVENT can HOST MANY CUSTOMER
My Hibernate Mapping for CUSTOMER_EVENT as below
Code:
<hibernate-mapping>
<class name="com.biz.CustomerEvent" table="CUSTOMER_EVENT">
<composite-id name="id" class="com.biz.CustomerEventId">
<key-property name="customerId" type="string">
<column name="CUSTOMER_ID" length="10" />
</key-property>
<key-property name="eventId" type="big_decimal">
<column name="EVENT_ID" precision="22" scale="0" />
</key-property>
</composite-id>
<many-to-one name="customer" class="com.biz.Customer" update="false" insert="false" fetch="select">
<column name="CUSTOMER_ID" length="10" not-null="true" />
</many-to-one>
<many-to-one name="event" class="com.biz.Event" update="false" insert="false" fetch="select">
<column name="EVENT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
The question is , lets say i want to list all customer name that participate in event id = 1
What i did is
Code:
select ce from CustomerEvent ce inner join ce.event as ide where
ide.eventId = 1
Above works well.. But when i do
Code:
select ce from CustomerEvent ce inner join ce.id as ide
where ide.eventId = 1
it gives me
org.hibernate.hql.ast.QuerySyntaxError: Invalid path: 'ide.eventId'
Is there any way to select from one of the composite id.
How to construct the HQL and the corressponding Criteria.
i do something like below
Code:
session.createCriteria(CustomerEvent.class)
.setAlias("id","cid")
.add(Restrictions.eq("cid.eventId",new Long(1))).list();
also give me exceptions...
Thanks