不知道是什么原因导致此错误...

我有一个名为StudentUnit的类,其中可以包含单元列表。

如果仅获取StudentUnit对象,则结果正常,但如果尝试获取Units(添加fetchType == eager),则将得到java.sql.SQLSyntaxErrorException:ORA-01722:无效数字

但是请注意,我映射到Unit的字段(unitCode,unitNm)都是Strings。我一直在想,将unitCode设置为@id或与此相关的东西是否可能是一个问题...

@Entity
@Table(name = "STUDENT_UNITS")
@NamedQuery (name ="StudentUnit.findByCourseAttemptNo",
query ="SELECT  su FROM StudentUnit su WHERE su.studentNo = :studentNo and su.courseNo = :courseNo and su.courseAttemptNo = :courseAttemptNo")
@FetchProfile(name = "studentUnit", fetchOverrides = { @FetchProfile.FetchOverride(entity = StudentUnit.class, association = "units", mode = FetchMode.JOIN) })
public class StudentUnit{

    @Id
    @Column(name = "STUDENT_NO")
    private Integer studentNo;


    @Column(name = "COURSE_NO")
    private Integer courseNo;


    @Column(name = "UNIT_CODE")
    private String unitCode;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "unitCode")//this one gives problems,which proves the issue is on Unit
    //@OneToMany(mappedBy = "unitCode"): this one is ok, once never tries to get the Unit
    private List<Unit> units;
}




@Entity
@Table(name="UNITS")
public class Unit {

    @Id
    @Column(name = "UNIT_CODE")
    private String unitCode;

    @Column(name = "UNIT_NM")
    private String unitNm;

    @Column(name = "GRADE_CODE_NO")
    private Integer gradeCodeNo;


    @Column(name = "IMPLEMENTATION_DATE")
    private Date implementationDate;

     //getters/setters

}


来自数据库的信息:

  STUDENT_UNITS
    (
      STUDENT_NO              NUMBER(10),
      COURSE_NO               NUMBER(5),
      COURSE_ATTEMPT_NO       NUMBER(5),
      UNIT_CODE               VARCHAR2(16 BYTE),
      ORIGINATING_DBKEY       NUMBER
    )

    UNITS
    (
      UNIT_CODE                 VARCHAR2(16 BYTE),
      UNIT_STEM                 VARCHAR2(15 BYTE),
      UNIT_ANTA_VERSION_NO      VARCHAR2(1 BYTE),
      UNIT_NM                   VARCHAR2(100 BYTE),
      IMPLEMENTATION_DATE       DATE
    )


更多错误日志:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
root cause

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:130)
    org.springframework.orm.hibernate4.HibernateExceptionTranslator.convertHibernateAccessException(HibernateExceptionTranslator.java:56)
    org.springframework.orm.hibernate4.HibernateExceptionTranslator.translateExceptionIfPossible(HibernateExceptionTranslator.java:43)
    org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
    org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    $Proxy207.findStudentUnits(Unknown Source)
    servicePack.service.student.StudentUnitsService.findStudentUnits(StudentUnitsService.java:21)
    servicePack.service.student.StudentUnitsService$$FastClassByCGLIB$$bfb0625f.invoke(<generated>)
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
    servicePack.service.student.StudentUnitsService$$EnhancerByCGLIB$$6133a5f5.findStudentUnits(<generated>)
    servicePack.controller.StudentUnitsController.retrieveStudentUnits(StudentUnitsController.java:37)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
root cause

org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
    org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
    org.hibernate.loader.Loader.getResultSet(Loader.java:2031)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
    org.hibernate.loader.Loader.doQuery(Loader.java:899)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:311)
    org.hibernate.loader.Loader.loadCollection(Loader.java:2228)
    org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:65)
    org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:674)
    org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:80)
    org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1848)
    org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:681)
    org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:1030)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:346)
    org.hibernate.loader.Loader.doList(Loader.java:2516)
    org.hibernate.loader.Loader.doList(Loader.java:2502)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
    org.hibernate.loader.Loader.list(Loader.java:2327)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
    org.hibernate.internal.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    myPack.StudentUnitsSearchDaoImpl.findStudentUnits(StudentUnitsSearchDaoImpl.java:44)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    $Proxy207.findStudentUnits(Unknown Source)
    servicePack.service.student.StudentUnitsService.findStudentUnits(StudentUnitsService.java:21)
    servicePack.service.student.StudentUnitsService$$FastClassByCGLIB$$bfb0625f.invoke(<generated>)
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
    servicePack.service.student.StudentUnitsService$$EnhancerByCGLIB$$6133a5f5.findStudentUnits(<generated>)
    servicePack.controller.StudentUnitsController.retrieveStudentUnits(StudentUnitsController.java:37)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
root cause

java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

    oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
    oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
    oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
    oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
    oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
    oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
    oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
    oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
    oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
    oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
    oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
    oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
    oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
    org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
    org.hibernate.loader.Loader.getResultSet(Loader.java:2031)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1832)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
    org.hibernate.loader.Loader.doQuery(Loader.java:899)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:311)
    org.hibernate.loader.Loader.loadCollection(Loader.java:2228)
    org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:65)
    org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:674)
    org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:80)
    org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1848)
    org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:681)
    org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:1030)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:346)
    org.hibernate.loader.Loader.doList(Loader.java:2516)
    org.hibernate.loader.Loader.doList(Loader.java:2502)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
    org.hibernate.loader.Loader.list(Loader.java:2327)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
    org.hibernate.internal.SessionImpl.list(SessionImpl.java:1268)
    org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    myPack.StudentUnitsSearchDaoImpl.findStudentUnits(StudentUnitsSearchDaoImpl.java:44)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    $Proxy207.findStudentUnits(Unknown Source)
    servicePack.service.student.StudentUnitsService.findStudentUnits(StudentUnitsService.java:21)
    servicePack.service.student.StudentUnitsService$$FastClassByCGLIB$$bfb0625f.invoke(<generated>)
    org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
    servicePack.service.student.StudentUnitsService$$EnhancerByCGLIB$$6133a5f5.findStudentUnits(<generated>)
    servicePack.controller.StudentUnitsController.retrieveStudentUnits(StudentUnitsController.java:37)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)


先感谢您,

泰国人

最佳答案

属性:

    mappedBy = "unitCode"


是错误的:mappedBy应该指向类StudentUnit的属性,而不是String。
因此,只需清除mappingBy =“ unitCode”或尝试进行双向映射,如下所示:

public class StudentUnit{

    ...

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "studentUnit")
    private List<Unit> units;
}

@Entity
@Table(name="UNITS")
public class Unit {

    @Id
    @Column(name = "UNIT_CODE")
    private String unitCode;

    @ManyToOne
    @JoinColumn(name="STUDENT_NO_ID")
    private StudentUnit studentUnit;

    @Column(name = "UNIT_NM")
    private String unitNm;
}

07-26 06:17