-->
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.  [ 2 posts ] 
Author Message
 Post subject: query on composite-Id containing wildcards
PostPosted: Mon Mar 20, 2006 10:39 am 
Newbie

Joined: Fri Nov 14, 2003 8:37 am
Posts: 14
Location: Hamburg - Germany
Hi Folks,

I try to generate a query with hibernate criterias on a mapping with a composite-id. I set the criteria as I think it should be, but the query then returns nothing :-(

As I can see on the relevant part of my sql-statement (just the where-clause) hibernate tries to set all three values of the composite-id whereas I only set only one value of the composite-id expecting the rest of the values be treated as wildcards.

My question: How can I create a query on that composite-id with my single value and the rest of the c-id as wildcards?

Thanks for any hints!

Regards,

Christian

Hibernate version: 3.1.2

Mapping documents:
<hibernate-mapping>
<class name="com.myapp.entities.RoleValue" table="ROLE_VALUES">
<composite-id name="id" class="com.myapp.entities.RoleValueId">
<key-property name="roleId" type="long">
<column name="ROLE_ID" precision="22" scale="0" />
</key-property>
<key-property name="roleValue" type="string">
<column name="ROLE_VALUE" />
</key-property>
<key-property name="roleType" type="long">
<column name="ROLE_TYPE" precision="22" scale="0" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Criteria roleValueCrt = session.createCriteria(RoleValue.class);
RoleValueId rvi = new RoleValueId();
rvi.setId(myRoleId);
roleValueCrt.add(Expression.eq("id", rvi));
List roleValueList = roleValueCrt.list();

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
[...] where (this_.ROLE_ID=? and this_.ROLE_VALUE=? and this_.ROLE_TYPE=?)


Top
 Profile  
 
 Post subject: Re: query on composite-Id containing wildcards
PostPosted: Mon Mar 20, 2006 2:13 pm 
Newbie

Joined: Fri Nov 14, 2003 8:37 am
Posts: 14
Location: Hamburg - Germany
cschlaefcke wrote:
Hi Folks,

I try to generate a query with hibernate criterias on a mapping with a composite-id. I set the criteria as I think it should be, but the query then returns nothing :-(

As I can see on the relevant part of my sql-statement (just the where-clause) hibernate tries to set all three values of the composite-id whereas I only set only one value of the composite-id expecting the rest of the values be treated as wildcards.

My question: How can I create a query on that composite-id with my single value and the rest of the c-id as wildcards?


Solved using Expression.sqlRestriction("id = " + myValue);

Regards,

Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.