Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

azerafati opened this issue Jan 17, 2015 · 6 comments
Labels
bug
Milestone

Comments

@azerafati
Copy link

@azerafati azerafati commented Jan 17, 2015

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
Copy link
Member

@timowest 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
Copy link

@mirceade mirceade commented Feb 26, 2015

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
Copy link
Member

@timowest timowest commented Feb 26, 2015

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

@mirceade
Copy link

@mirceade mirceade commented Feb 26, 2015

Thank you for your great work Timo!

@azerafati
Copy link
Author

@azerafati azerafati commented Feb 26, 2015

Yea, Thank you guys!

@timowest
Copy link
Member

@timowest 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.