javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法用oracle执行查询

时间:2015-08-26 14:11:09

标签: java spring oracle hibernate jpa

我正在尝试从表中删除或选择数据,因为我使用的是Spring数据JPA。

我面临的例外是“javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query

下面给出的完整堆栈跟踪

Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
    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.getResultList(QueryImpl.java:458)
    at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67)
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:291)
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.deleteAll(SimpleJpaRepository.java:198)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:416)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:401)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:373)
    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$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
    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:207)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.jbehave.core.steps.StepCreator$MethodInvoker.invoke(StepCreator.java:671)
    at org.jbehave.core.steps.StepCreator$BeforeOrAfterStep.perform(StepCreator.java:458)
    ... 12 more
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
    at org.hibernate.loader.Loader.doList(Loader.java:2557)
    at org.hibernate.loader.Loader.doList(Loader.java:2540)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
    at org.hibernate.loader.Loader.list(Loader.java:2365)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
    ... 42 more
Caused by: java.sql.SQLException: Fail to convert to internal representation
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:403)
    at oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:252)
    at oracle.jdbc.driver.T4CVarcharAccessor.getLong(T4CVarcharAccessor.java:813)
    at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:743)
    at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:440)
    at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:278)
    at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:278)
    at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:278)
    at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:74)
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
    at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
    at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:338)
    at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
    at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1696)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1628)
    at org.hibernate.loader.Loader.getRow(Loader.java:1515)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:726)
    at org.hibernate.loader.Loader.processResultSet(Loader.java:953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:921)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
    at org.hibernate.loader.Loader.doList(Loader.java:2554)
    ... 52 more

实体类如下所述

@Entity
    @Table(name = "EMPLOYEE")
    public class Employee {

        @Id
        @Column(name = "ID")
        private Long id;

        @Column(name = "EMPLOYEE_ID")
        private Long employeeId;

        @Column(name = "EMPLOYEE_TYPE")
        private String employeeType;



        public void setId(Long id) {
            this.id = id;
        }

        public void setEmployeeId(Long employeeId) {
            this.employeeId = employeeId;
        }

        public void setEmployeeType(String employeeType) {
            this.employeeType = employeeType;
        }
    }

存储库类是

public interface EmployeeRepository extends JpaRepository<EMPLOYEE, Long> {
}

执行以下查询

EmployeeRepository empRepo;
empRepo.deleteAll();
表设计如下:

    CREATE TABLE DB.EMPLOYEE
(
  ID              NUMBER(19)                    NOT NULL,
  EMPLOYEE_ID       VARCHAR2(255 CHAR),
  EMPLOYEE_TYPE  VARCHAR2(255 CHAR)
)

请建议。

1 个答案:

答案 0 :(得分:0)

感谢Maciej发布的帖子已被删除我不知道怎么样:)我已经在你的建议的帮助下解决了这个问题,我在做错了 如果与表设计进行比较,EMPLOYEE_ID的数据类型在实体类中是不同的。