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