0
私はPostgreSQLでスプリングブートを使用しています。私はExcelシートからデータを抽出し、JPAを使用してデータベースに保存します。 JPAを使用してクエリを実行しようとすると、エラーが発生します。エラー:演算子が存在しません:テキスト=整数
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クラス
@Entity
@Table(name = "corporate_cluster", schema = "TARGET")
public class CorporateClusterDto {
@Id
private Integer cls_id;
private.....
}
2.Repository
ここでは、クラスのコードスニペット が、私はExcelシートの最初のセルからデータを取得したい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とそれがテーブルに存在するかどうかを確認します。私は1.0036399E7のような指数値を避けたい、私は10036399のような形式でそれらをしたい、だから私は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)
よく 'text_'型の' corporate_cluster'テーブルの 'cls_id'列ですか?また、あなたの 'BigDecimal'の根拠は非常に奇妙です。なぜ' int'を使うか、適切な書式で表示するのですか? –
'Decluster'とは何ですか? – Andreas