querydsl instanceof results in wrong query for Type(?1) #1123

Closed
azerafati opened this Issue Jan 17, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@azerafati

copied from SE (http://stackoverflow.com/questions/27941534/)

If I use Hibernate entity Inheritance feature, I could easily always try to load only the subClass I need like this

SELECT p FROM Product p WHERE TYPE(p) = ?1

trying to achieve the same query with queryDSL:

QProduct.product.instanceOfAny(clazz)

But I get the following exception

Caused by: java.lang.IllegalArgumentException: Parameter value [Product] did not match expected type [java.lang.Integer (n/a)]

query that querydsl produces is

SELECT count(product)
FROM Product product
WHERE product.class = ?1  // this should be TYPE(product) = ?1

my enitity

@Entity
@Table(name = "product")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Product {

    ...

Full Stack Trace (for a similar case but different Class name):

Caused by: java.lang.IllegalArgumentException: Parameter value [BasketDiscount] did not match expected type [java.lang.Integer (n/a)]
    at org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryImpl.java:874)
    at org.hibernate.jpa.internal.QueryImpl.access$000(QueryImpl.java:80)
    at org.hibernate.jpa.internal.QueryImpl$ParameterRegistrationImpl.bindValue(QueryImpl.java:248)
    at org.hibernate.jpa.internal.QueryImpl$JpaPositionalParameterRegistrationImpl.bindValue(QueryImpl.java:337)
    at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:674)
    at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:198)
    at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:49)
    at com.mysema.query.jpa.impl.JPAUtil.setConstants(JPAUtil.java:55)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:128)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.count(AbstractJPAQuery.java:79)
    at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.findAll(QueryDslJpaRepository.java:125)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:442)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:427)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:381)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    ... 94 more
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jan 17, 2015

Member

The attached PR removes the HQLTemplates customizations to use the .class legacy syntax, since Hibernate 4 supports now the official JPA 2.0 type(?) syntax.

Member

timowest commented Jan 17, 2015

The attached PR removes the HQLTemplates customizations to use the .class legacy syntax, since Hibernate 4 supports now the official JPA 2.0 type(?) syntax.

@mirceade

This comment has been minimized.

Show comment
Hide comment
@mirceade

mirceade Feb 26, 2015

Hi,
Do we have a release where this fix was/will be integrated?

Hi,
Do we have a release where this fix was/will be integrated?

@timowest timowest added this to the 3.6.2 milestone Feb 26, 2015

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 26, 2015

Member

It should be available in 3.6.2, which will be released this weekend.

Member

timowest commented Feb 26, 2015

It should be available in 3.6.2, which will be released this weekend.

@mirceade

This comment has been minimized.

Show comment
Hide comment
@mirceade

mirceade Feb 26, 2015

Thank you for your great work Timo!

Thank you for your great work Timo!

@azerafati

This comment has been minimized.

Show comment
Hide comment
@azerafati

azerafati Feb 26, 2015

Yea, Thank you guys!

Yea, Thank you guys!

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 28, 2015

Member

Released in 3.6.2

Member

timowest commented Feb 28, 2015

Released in 3.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment