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