-->
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: Unable to pass class parameter in JPQL TYPE(alias) function
PostPosted: Wed May 19, 2010 2:39 pm 
Newbie

Joined: Fri Jan 23, 2004 3:37 pm
Posts: 14
Hi.
I'm using Hibernate 3.5.1 as JPA provider, and having problems passing the TYPE(alias) class as parameter.
The following query works:
Code:
select c from Cat c where type(c) = DomesticCat

However, passing the type as parameter, does not:
Code:
Query query = em.createQuery("select c from Cat c where type(c) = :t");
query.setParameter("t", DomesticCat.class);
List l = query.getResultList()


I have the following stack trace:
Code:
Caused by: java.lang.UnsupportedOperationException: At the moment this type is not the one actually used to map the discriminator.
   at org.hibernate.persister.entity.DiscriminatorType.nullSafeSet(DiscriminatorType.java:111)
   at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
   at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
   at org.hibernate.loader.Loader.doQuery(Loader.java:717)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
   at org.hibernate.loader.Loader.doList(Loader.java:2294)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
   at org.hibernate.loader.Loader.list(Loader.java:2167)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:236)


Things don't seems good, as here's the code for the DiscriminatorType's method:
Code:
   public void nullSafeSet(
         PreparedStatement st,
         Object value,
         int index,
         SessionImplementor session) throws HibernateException, SQLException {
      throw new UnsupportedOperationException(
            "At the moment this type is not the one actually used to map the discriminator."
      );
   }


Am I getting something wrong or Hibernate should support this to be JPA 2 compatible? Here are some examples from JPA 2 spec, including type parameters:
Code:
SELECT e
FROM Employee e
WHERE TYPE(e) IN (Exempt, Contractor)

SELECT e
FROM Employee e
WHERE TYPE(e) IN (:empType1, :empType2)

SELECT e
FROM Employee e
WHERE TYPE(e) IN :empTypes

SELECT TYPE(e)
FROM Employee e
WHERE TYPE(e) <> Exempt


Top
 Profile  
 
 Post subject: Re: Unable to pass class parameter in JPQL TYPE(alias) function
PostPosted: Fri Mar 18, 2011 11:56 pm 
Newbie

Joined: Mon Sep 01, 2003 9:48 pm
Posts: 17
I'm also seeing this problem.


Top
 Profile  
 
 Post subject: Re: Unable to pass class parameter in JPQL TYPE(alias) function
PostPosted: Tue May 24, 2011 11:16 am 
Newbie

Joined: Tue May 24, 2011 9:13 am
Posts: 1
Very interested in a solution too, seems there is a bug pending
http://opensource.atlassian.com/project ... e/HHH-4881


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.