-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Composite key criteria - restriction behavior
PostPosted: Mon Mar 27, 2006 2:59 pm 
Newbie

Joined: Fri Mar 24, 2006 5:44 pm
Posts: 6
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 3:09 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
cant' you just call the fields by name without the comp_id prefix?

restrictions.eq("userId","xyz");
restrictions.eq("nameSpace","123");

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 3:21 pm 
Newbie

Joined: Fri Mar 24, 2006 5:44 pm
Posts: 6
kochcp wrote:
cant' you just call the fields by name without the comp_id prefix?

restrictions.eq("userId","xyz");
restrictions.eq("nameSpace","123");



Its weird but if i did what you suggested then the select query itself doesnt seem to be executed,no query being printed on the console at all.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.