ERROR: operator does not exist: text = integer

时间:2016-08-30 04:17:47

标签: java postgresql hibernate jpa

I am using Spring boot with Postgresql. I want to extract data from excel sheet and save it to database using JPA. When I try to fire the query using JPA I get the error.

ERROR: operator does not exist: text = integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 59

1.Entity class

@Entity
@Table(name = "corporate_cluster", schema = "TARGET")  
public class CorporateClusterDto {

    @Id
    private Integer cls_id;
    private.....

}

2.Repository

public interface CorporateClusterRepository extends
            JpaRepository<Decluster, Long> {

    @Query(value = "SELECT EXISTS(SELECT 1 FROM corporate_cluster WHERE cls_id=?1)", nativeQuery = true)
    public Boolean existsByClsId(Integer cls_id);

}

3.Service class code snippet Here, I want to get data from first cell of the excel sheet and check whether it exists in the table. I want to avoid exponential values like 1.0036399E7, I want them in format like 10036399, that's why I used BigDecimal.

public class FileUploadService {

    public void upload(){
        boolean isOldClsCorporateCluster = corporateClusterRepository.existsByClsId(new BigDecimal(row.getCell(0).getNumericCellValue()).intValue());
    }
}

4.Stacktrace:

Hibernate: SELECT EXISTS(SELECT 1 FROM corporate_cluster WHERE cls_id=?)
2016-08-30 09:20:02.969  WARN 532 --- [nio-8084-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42883
2016-08-30 09:20:02.970 ERROR 532 --- [nio-8084-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: operator does not exist: text = integer
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 59
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
    at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:524)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:100)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:91)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:462)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy99.existsByClsId(Unknown Source)

1 个答案:

答案 0 :(得分:0)

异常表示text = integer意味着你有使用int(在一侧)和text(在第二面)字段上加入字段的表 - 它将失败。请再次检查DDL。