Hibernate version: 3.1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 10, 2006 6:09:36 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping package="com.dowjones.wealthmanager.customer.clientinformation.dataaccess">
<class name="Client" table="TB_CLIENT" schema="CUSTOMER">
<composite-id name="id" class="ClientId"> <key-property name="userId" type="string"> <column name="USER_ID" length="10" /> </key-property> <key-property name="nameSpace" type="string"> <column name="NAME_SPACE" length="10" /> </key-property> <key-property name="clientId" type="string"> <column name="CLIENT_ID" length="25" /> </key-property> </composite-id> <property name="firstName" type="string">
<column name="FIRST_NAME" length="25" not-null="true" />
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="25" not-null="true" />
</property>
<property name="emailIdPrimary" type="string">
<column name="EMAIL_ID_PRIMARY" length="10" not-null="true" />
</property>
<property name="companyName" type="string">
<column name="COMPANY_NAME" length="10" not-null="true" />
</property>
<property name="address1" type="string">
<column name="ADDRESS1" length="10" not-null="true" />
</property>
.....
.....
.....
<set name="tbUserClients" inverse="true">
<key>
<column name="USER_ID" length="10" not-null="true" />
<column name="NAME_SPACE" length="10" not-null="true" />
<column name="CLIENT_ID" length="25" not-null="true" />
</key>
<one-to-many class="UserClient" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(Client.class);
criteria.add(Restrictions.eq("id.userId","xyz")); criteria.add(Restrictions.eq("id.nameSpace","123"));
Name and version of the database you are using:O racle 10g
The generated SQL (show_sql=true):
select
this_.USER_ID as USER1_7_0_, this_.NAME_SPACE as NAME2_7_0_, this_.CLIENT_ID as CLIENT3_7_0_, this_.FIRST_NAME as FIRST4_7_0_, this_.LAST_NAME as LAST5_7_0_, this_.EMAIL_ID_PRIMARY as EMAIL6_7_0_, this_.COMPANY_NAME as COMPANY7_7_0_, this_.ADDRESS1 as ADDRESS8_7_0_, this_.EXTERNAL_ID as EXTERNAL9_7_0_, this_.ADDRESS2 as ADDRESS10_7_0_, this_.CITY as CITY7_0_, this_.STATE as STATE7_0_, this_.ZIP as ZIP7_0_, this_.COUNTRY as COUNTRY7_0_, this_.CONTACT_MAIN as CONTACT15_7_0_, this_.STATE_OTHER as STATE16_7_0_, this_.NOTES_ID as NOTES17_7_0_, this_.PRIORITY as PRIORITY7_0_, this_.PREFIX as PREFIX7_0_, this_.SECOND_ADDRESS1 as SECOND20_7_0_, this_.SUFFIX as SUFFIX7_0_, this_.SECOND_ADDRESS2 as SECOND22_7_0_, this_.NICK_NAME as NICK23_7_0_, this_.SECOND_CITY as SECOND24_7_0_, this_.MIDDLE_NAME as MIDDLE25_7_0_, this_.SECOND_STATE as SECOND26_7_0_, this_.JOB_TITLE as JOB27_7_0_, this_.SECOND_STATE_OTHER as SECOND28_7_0_, this_.HOME_PHONE as HOME29_7_0_, this_.SECOND_ZIP as SECOND30_7_0_, this_.WORK_PHONE as WORK31_7_0_, this_.SECOND_COUNTRY as SECOND32_7_0_, this_.CELL_PHONE as CELL33_7_0_, this_.FAX as FAX7_0_, this_.EMAIL_ID_SECONDARY as EMAIL35_7_0_, this_.OTHER_INFO as OTHER36_7_0_, this_.CREATION_TIME_STAMP as CREATION37_7_0_, this_.CREATE_BY_ID as CREATE38_7_0_, this_.MODIFICATION_TIME_STAMP as MODIFIC39_7_0_, this_.MODIFIED_BY_ID as MODIFIED40_7_0_, this_.WORK_PHONE_EXT as WORK41_7_0_, this_.OTHER_PHONE as OTHER42_7_0_, this_.OTHER_PHONE_EXT as OTHER43_7_0_, this_.CREATED_BY_NS as CREATED44_7_0_, this_.MODIFIED_BY_NS as MODIFIED45_7_0_
from CUSTOMER.TB_CLIENT this_ where this_.USER_ID=? and this_.NAME_SPACE=?
Problem: I am trying to retrieve all clients for a user id and namespace combination but the values that I pass for the columns user id and namespace doesnt seem to form part of the query thats being finally executed.This is happening for any column which forms part of the composite key and on which I want to create a restriction. If i specify a non-composite key column as a Restriction things are working completely fine.
What needs to be done to achieve this functionality where I can specify a "where" clause for a column which forms part of a composite key?
|