.ClassCastException:org.hibernate.internal.SQLQueryImpl无法强制转换为org.hibernate.internal.QueryImpl

时间:2016-11-17 04:26:11

标签: spring-data-jpa jpql eager-loading jpa-2.1 entitygraph

我试图使用EntityGraph

获取一些Lazy集合

在我的实体上

@Entity
@Table
......
 @NamedEntityGraph(name = "getDetails", attributeNodes = { @NamedAttributeNode(value = "prices") })
    @NamedNativeQuery(name = "MyTable.getData", query = "SELECT * FROM MyTable", resultClass = MyTable.class)

存储库

@Query(nativeQuery = true)
    @EntityGraph(value = "getDetails", type = EntityGraphType.FETCH)
            MyTable findData();

使用本机查询时,我得到了下一个异常

  

java.lang.ClassCastException:org.hibernate.internal.SQLQueryImpl无法强制转换为org.hibernate.internal.QueryImpl       在org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:604)       在org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:529)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在org.springframework.orm.jpa.SharedEntityManagerCreator $ DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:372)       at com.sun.proxy。$ Proxy276.getSingleResult(Unknown Source)       在org.springframework.data.jpa.repository.query.JpaQueryExecution $ SingleEntityExecution.doExecute(JpaQueryExecution.java:206)       在org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)       在org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:102)       在org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:92)       at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)       at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)       在org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)       在 ................................................. ....       at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)       在java.lang.Thread.run(Thread.java:745)

使用JPQL查询时一切正常。但我有一个很大的原生查询,这是非常痛苦的转换为JPQL。在这种情况下有谁知道解决方法?将不胜感激任何帮助。

0 个答案:

没有答案