InvalidDataAccessResourceUsageException:无法提取ResultSet

时间:2016-05-30 13:02:07

标签: java hibernate jpa oracle11g

简介

我继承了一个项目,我正在尝试进行更改。 Web应用程序正常工作,直到我将以下字段和方法添加到实体。

@Lob
@Column(name = "FIELDS")
private String partnerFields;

public String getPartnerFields() {
    return partnerFields;
}

public void setPartnerFields(String partnerFields) {
    this.partnerFields = partnerFields;
}

错误

添加这些后,我收到以下错误:

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]

其他信息

代码是专有的,所以我不能发布它,但我还可以添加错误发生在findAll方法调用中,该调用将Specification作为参数。

1。 findAll Invocation

抛出异常的行:

return partnerRepository.findAll(PartnerSpecifications.isForSelection(selectionFilter), pageable);

这称为这种特定的JPA方法:

enter image description here

2。 Hibernate显示的SQL语句

以下是已删除大部分列的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 )
               )

LOB导致此错误的任何想法?

我当前的解决方法

我目前的解决方法是让另一个实体持有LOB,并与原始实体进行1对1的映射:

在我的原始实体中:

 @OneToOne(cascade = CascadeType.ALL, mappedBy = "partner")
    private PartnerFieldsEntity partnerFieldsEntity;

我的新实体(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());
    }

}

1 个答案:

答案 0 :(得分:1)

Oracle 10中的

SELECT DISTINCT需要UNIONCLOB不支持此功能。您必须使用DISTINCT的替代方案。另外,请勿在{{1​​}}语句中包含CLOB列。