-->
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: Problem with binding parameter in polymorphic query
PostPosted: Mon Dec 17, 2007 5:52 am 
Newbie

Joined: Mon Dec 17, 2007 5:40 am
Posts: 1
I am trying to issue a named query where one of the bind parameter is a "class".

This would be the same as doing:
select cat
from Cat cat where cat.class = ?1

but when I try to execute the query where the binding as been done with query.setParameter(1, DomesticCat.class)

I first get a INFO log:
INFO [org.hibernate.type.IntegerType] could not bind value 'class test.DomesticCat' to parameter: 1; java.lang.Class cannot be cast to java.lang.Integer

and then the following exception:
java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.Integer
at org.hibernate.type.IntegerType.set(IntegerType.java:41)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)....

Is it possible to achieve the binding defined above ?

thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 6:17 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
See Hibernate docs Ch 14: "Likewise, the special property class accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value."

I believe this means you cannot use a Java Class object as parameter any way. But even the class name wouldn't work as this is only supported if directly embedded. When using a query parameter you have to pass in the discriminator value as defined in the mapping data for the DomesticCat entity.


Top
 Profile  
 
 Post subject: Re: Problem with binding parameter in polymorphic query
PostPosted: Thu May 21, 2009 4:59 am 
Newbie

Joined: Wed Aug 06, 2008 4:00 pm
Posts: 4
I had also the same problem and the documentation is totally unclear.
It is expecting an Integer but in the doc they are using String value !!!


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.