gpt4 book ai didi

hibernate - querydsl instanceof 导致对 hibernate Type(1) 的错误查询

转载 作者:行者123 更新时间:2023-12-04 02:54:08 25 4
gpt4 key购买 nike

如果我使用 Hibernate Inheritance 实体,我总是可以很容易地尝试只加载我需要的子类,就像这样

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

尝试使用 queryDSL 实现相同的查询:

QProduct.product.instanceOfAny(clazz)

但我得到以下异常

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

querydsl 产生的查询是

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

我的实体

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

...

完整堆栈跟踪(对于类似情况但类名不同):

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

最佳答案

querydsl github repository中讨论并解决了这个问题,

作为@Timo mentions修复将使用版本 3.6.2

It should be available in 3.6.2

关于hibernate - querydsl instanceof 导致对 hibernate Type(1) 的错误查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27941534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com