java InvalidDataAccessResourceUsageException: 无法提取 ResultSet
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37526374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
InvalidDataAccessResourceUsageException: could not extract ResultSet
提问by Menios
Intro
介绍
I have inherited a project and am trying to make changes. The web application works fine until I add the following field and methods to the Entity.
我继承了一个项目,正在尝试进行更改。在我将以下字段和方法添加到实体之前,Web 应用程序工作正常。
@Lob
@Column(name = "FIELDS")
private String partnerFields;
public String getPartnerFields() {
return partnerFields;
}
public void setPartnerFields(String partnerFields) {
this.partnerFields = partnerFields;
}
Error
错误
After adding these, I get the following errors:
添加这些后,我收到以下错误:
2016-05-30 15:36:40,550 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] SQL Error: 932, SQLState: 42000
2016-05-30 15:36:40,550 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] ORA-00932: inconsistent datatypes: expected - got CLOB
raised org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:172) ~[spring-orm-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:155) ~[spring-orm-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417) ~[spring-orm-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111) ~[spring-data-jpa-1.7.0.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at com.sun.proxy.$Proxy73.findAll(Unknown Source) ~[na:na]
Additional Information
附加信息
The code is proprietary so I can't post it all but I can also add that the error takes place in a findAll
method invocation that takes a Specification
as a param.
该代码是专有的,所以我不能全部发布,但我还可以补充说,错误发生在findAll
将 aSpecification
作为参数的方法调用中。
1. findAll Invocation
1. findAll 调用
Line where exception is thrown:
抛出异常的行:
return partnerRepository.findAll(PartnerSpecifications.isForSelection(selectionFilter), pageable);
Which is called this specific JPA method:
这称为这种特定的 JPA 方法:
2. SQL Statement Displayed by Hibernate
2、Hibernate显示的SQL语句
Below is an edited version of the SQL statement with most of the columns removed:
下面是删除了大部分列的 SQL 语句的编辑版本:
SELECT *
FROM (SELECT DISTINCT partnerent0_.partner_id AS
PARTNER_ID1_16_,
...
FROM partner partnerent0_,
partner_id partneride1_
WHERE partnerent0_.id = partneride1_.id
AND ( partnerent0_.status IS NOT NULL )
AND partnerent0_.status <>?
AND ( partneride1_.identifier LIKE ? )
AND ( partnerent0_.cat2016 <>? OR partnerent0_.category_2016 IS NULL )
)
Any ideas why LOB
would be causing this error?
任何想法为什么LOB
会导致此错误?
My Current Workaround
我目前的解决方法
My current workaround was to make another entity to hold the LOB, and make a 1 to 1 mapping to the original entity:
我当前的解决方法是创建另一个实体来保存 LOB,并与原始实体进行 1 对 1 映射:
In my original entity:
在我的原始实体中:
@OneToOne(cascade = CascadeType.ALL, mappedBy = "partner")
private PartnerFieldsEntity partnerFieldsEntity;
My new entity (1 to 1):
我的新实体(1 对 1):
@Entity
@Table(name="PARTNER_FIELDS")
public class PartnerFieldsEntity{
@Id
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARTNER_ID", nullable = false)
private PartnerEntity partner;
@Lob
@Column(name = "FIELDS")
private String partnerFields;
public PartnerEntity getPartner() {
return partner;
}
public void setPartner(PartnerEntity partner) {
this.partner = partner;
}
public String getPartnerFields() {
return partnerFields;
}
public void setPartnerFields(String partnerFields) {
this.partnerFields = partnerFields;
}
public void setPartnerFields(PartnerFieldsWrapper projectFields) {
setPartnerFields(projectFields.toJson());
}
}
采纳答案by ChrisGeo
SELECT DISTINCT
in Oracle 10 requires a UNION
and this is not supported for CLOB
. You will have to use alternatives to DISTINCT
. Additionally do not include the CLOB
column in WHERE
statements.
SELECT DISTINCT
在 Oracle 10 中需要一个UNION
,而CLOB
. 您将不得不使用DISTINCT
. 另外不要CLOB
在WHERE
语句中包含该列。