-->
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.  [ 1 post ] 
Author Message
 Post subject: detachedcriteria & restriction by class problem
PostPosted: Wed Jun 11, 2008 12:30 pm 
Newbie

Joined: Thu May 05, 2005 10:19 am
Posts: 3
Hibernate version: 3.1.3
database: Oracle 10g

I've got a DetachedCriteria query as follows (note the Restrictions.ne("class"...):


DetachedCriteria criteria = DetachedCriteria.forClass(PantryFood.class);
criteria.add(Property.forName("pantry").eq(pantry))
.createCriteria("foodServing.food")
.add(Restrictions.like("title", freetext, MatchMode.ANYWHERE))
.add(Restrictions.ne("class", Recipe.class))
.addOrder(Order.asc("title"));


This produces the following SQL (no problem here):

select
this_.pantry_food_id as pantry1_20_1_,
this_.pantry_id as pantry2_20_1_,
this_.food_id as food3_20_1_,
...
from
pantry_food this_
inner join
food food1_
on this_.food_id=food1_.food_id
where
this_.pantry_id=?
and food1_.title like ?
and food1_.FOOD_TYPE_CODE<>?
order by
food1_.title asc


The problem appears with the value that gets bound to the "class" restriction-- RECIPE, which is the correct discriminator value, is wrapped in two sets of singlequotes rather than just one:

13030 [2008-06-11 11:59:38,442] [main] DEBUG org.hibernate.type.LongType - binding '55276' to parameter: 1
13030 [2008-06-11 11:59:38,442] [main] DEBUG org.hibernate.type.StringType - binding '%cheese%' to parameter: 2
13046 [2008-06-11 11:59:38,458] [main] DEBUG org.hibernate.type.StringType - binding ''RECIPE'' to parameter: 3


I suppose I can do something similar with a sqlRestriction, but I'd love to understand why this is happening. Can anyone clarify?


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

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.