-->
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: Querying against a collection of values
PostPosted: Tue Apr 01, 2008 8:25 am 
Newbie

Joined: Wed May 25, 2005 1:47 pm
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate 3.2.5 connecting to MS SQL Server 2005


Code:
    <class name="com.xx.domain.entity.Promotion" table="promos" >
        <id name="promotionId" type="int" column="promo_id" >
            <generator class="identity"></generator>
        </id>         
   <set name="reviewCategories" table="promo_review_categories"  fetch="join" >
      <key column="promo_id"/>
      <element type="string" column="category_name"  >               
      </element>
   </set>
   
   </class>



I want to get all the Promotions that have a reviewCategory of 'Children' so I'm trying to run the following hql query:

Code:
from Promotion p where p.reviewCategories='Children'


which blows up with the following:

org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Set(com.xx.domain.entity.Promotion.reviewCategories) : string]

I've tried:

Code:
from Promotion p where p.reviewCategories.id='Children'


and:

Code:
from Promotion p where p.reviewCategories.value='Children'


both of which blow up with:
org.hibernate.QueryException: illegal attempt to dereference collection

I've tried:

Code:
from Promotion p where p.reviewCategories.category_name='Children'



which blows up with:

org.hibernate.QueryException: cannot dereference scalar collection element: category_name

I know I must be making some sort of obvious mistake but for the life of me I can't see what it is. Can anyone help????

Thanks

T

I've just noticed some thing else. If I change the query to:


Code:
from Promotion p where p.reviewCategories=:category


and do:
Code:
q.setString("category","Children");


Hibernate generates the following sql:

Code:
select promotion0_.promo_id as promo1_3_ from promos promotion0_, promo_review_categories reviewcate1_ where promotion0_.promo_id=reviewcate1_.promo_id and .=?


Which is suppose is an improvement, as it never got as far as generating any sql before. Trouble is its invalid.

Yours in Confusion

Tom


Top
 Profile  
 
 Post subject: Re: Querying against a collection of values
PostPosted: Tue Apr 01, 2008 10:52 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
This might work for you:


Code:
select distinct p from Promotion p inner join p.reviewCategories cat where cat='Children'



I've never tried it with elements but give it a try.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 11:19 am 
Newbie

Joined: Wed May 25, 2005 1:47 pm
Posts: 9
Well what do you know?

Code:

from Promotion p inner join p.reviewCategories cat where cat='Children'


works. But

Code:
from Promotion p inner join p.reviewCategories  where p.reviewCategories ='Children'


doesn't.

Thanks for that, Farzad

T


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.