当前位置: 首页 > 知识库问答 >
问题:

单元测试引发:HsqlException用户缺乏权限或未找到对象:ROWNUM

霍襦宗
2023-03-14
org.springframework.dao.InvalidDataAccessResourceUsageException: 
user lacks privilege or object not found: ROWNUM; SQL [n/a];

nested exception is org.hibernate.exception.SQLGrammarException: 
user lacks privilege or object not found: ROWNUM

....

Caused by: org.hsqldb.HsqlException: 
user lacks privilege or object not found: ROWNUM

我正在测试的功能在生产环境中工作得很好,但我不知道为什么在测试时不是这样。

下面是引发错误的测试函数:

@Override
public EvaluationCriteria findByCriteriaIdAndEvaluationId(Long evaluationId, Long criteriaId) {

    JPAQuery query = new JPAQuery(getEntityManager());

    QEvaluationCriteria evaluationCriteria = QEvaluationCriteria.evaluationCriteria;

    return query.from(evaluationCriteria)
                .where(evaluationCriteria.evaluation.id.eq(evaluationId))
                .where(evaluationCriteria.criteria.id.eq(criteriaId))
                .singleResult(evaluationCriteria);
}

我的测试:

@Test
public void findByCriteriaIdAndEvaluationId() {

    Long evaluationId = (long)1;
    Long criteriaId   = (long)1;

    EvaluationCriteria result = null;
    result = evaluationCriteriaDAO.findByCriteriaIdAndEvaluationId(evaluationId, criteriaId);

    Assert.assertNotNull(result);
}
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "SFINX_EVALUATION_CRITERIA", uniqueConstraints = @UniqueConstraint(columnNames = { "CRITERIA_ID", "EVALUATION_ID" }))
public class EvaluationCriteria implements Identifiable<Long> {

    private static final long serialVersionUID = 6254229189011963873L;
    private static final String SEQ_GENERATOR_NAME = "EvaluationCriteriaSeq";

    private Long id;
    private Criteria criteria;
    private Evaluation evaluation;

    @Override
    @Id
    @SequenceGenerator(name = SEQ_GENERATOR_NAME, initialValue = 1, sequenceName = "SFINX_EVALUATION_CRITERIA_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQ_GENERATOR_NAME)
    @Column(name = "ID", updatable = false)
    public Long getId() {
        return id;
    }

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

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Criteria.class)
    @JoinColumn(name = "CRITERIA_ID", nullable = false)
    public Criteria getCriteria() {
        return criteria;
    }

    public void setCriteria(Criteria criteria) {
        this.criteria = criteria;
    }

    @ManyToOne(fetch = FetchType.LAZY, targetEntity = Evaluation.class)
    @JoinColumn(name = "EVALUATION_ID", nullable = false)
    public Evaluation getEvaluation() {
        return evaluation;
    }

    public void setEvaluation(Evaluation evaluation) {
        this.evaluation = evaluation;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="testDaoUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>org.springframework.ldap.core.LdapTemplate</class>
        <class>net.gdcw.sfinx.domain.Employee</class>
        <class>net.gdcw.sfinx.domain.Criteria</class>
        <class>net.gdcw.sfinx.domain.CriteriaType</class>
        <class>net.gdcw.sfinx.domain.CriteriaTypeItem</class>
        <class>net.gdcw.sfinx.domain.EmployeeEvaluation</class>
        <class>net.gdcw.sfinx.domain.Evaluation</class>
        <class>net.gdcw.sfinx.domain.EvaluationCriteria</class>
        <class>net.gdcw.sfinx.domain.Feedback</class>
        <class>net.gdcw.sfinx.domain.Project</class>
        <class>net.gdcw.sfinx.domain.ProjectEmployee</class>
        <class>net.gdcw.sfinx.domain.Role</class>
        <class>net.gdcw.sfinx.domain.SystemRole</class>
        <class>net.gdcw.sfinx.domain.ImprovementProposal</class>
        <class>net.gdcw.sfinx.domain.Department</class>

        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="use_sql_comments" value="true"/>
            <!-- cache properties -->
            <property name="hibernate.cache.use_second_level_cache" value="true" />
            <property name="show_sql" value="true"/>
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.cache.region.factory_class"
                      value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
            <property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache.xml" />
        </properties>
    </persistence-unit>

</persistence>
Hibernate: drop table SFINX_CRITERIA cascade constraints
Hibernate: drop table SFINX_CRITERIA_TYPE cascade constraints
Hibernate: drop table SFINX_CRITERIA_TYPE_ITEM cascade constraints
Hibernate: drop table SFINX_DEPARTMENT cascade constraints
Hibernate: drop table SFINX_EMPLOYEE cascade constraints
Hibernate: drop table SFINX_EMPLOYEE_EVALUATION cascade constraints
Hibernate: drop table SFINX_EMPLOYEE_SYSTEM_ROLE cascade constraints
Hibernate: drop table SFINX_EVALUATION cascade constraints
Hibernate: drop table SFINX_EVALUATION_CRITERIA cascade constraints
Hibernate: drop table SFINX_EVALUATION_MANAGER cascade constraints
Hibernate: drop table SFINX_EVALUATION_VIEWER cascade constraints
Hibernate: drop table SFINX_FEEDBACK cascade constraints
Hibernate: drop table SFINX_IMPROVEMENT_PROPOSAL cascade constraints
Hibernate: drop table SFINX_PROJECT cascade constraints
Hibernate: drop table SFINX_PROJECT_EMPLOYEE cascade constraints
Hibernate: drop table SFINX_ROLE cascade constraints
Hibernate: drop table SFINX_SYSTEM_ROLE cascade constraints
Hibernate: drop sequence SFINX_CRITERIA_SEQ
Hibernate: drop sequence SFINX_CRITERIA_TYPE_ITEM_SEQ
Hibernate: drop sequence SFINX_CRITERIA_TYPE_SEQ
Hibernate: drop sequence SFINX_DEPARTMENT_SEQ
Hibernate: drop sequence SFINX_EMPLOYEE_EVALUATION_SEQ
Hibernate: drop sequence SFINX_EMPLOYEE_SEQ
Hibernate: drop sequence SFINX_EVALUATION_CRITERIA_SEQ
Hibernate: drop sequence SFINX_EVALUATION_SEQ
Hibernate: drop sequence SFINX_FEEDBACK_SEQ
Hibernate: drop sequence SFINX_IMPROVEMENT_PROPOSAL_SEQ
Hibernate: drop sequence SFINX_PROJECT_EMPLOYEE_SEQ
Hibernate: drop sequence SFINX_PROJECT_SEQ
Hibernate: drop sequence SFINX_ROLE_SEQ
Hibernate: drop sequence SFINX_SYSTEM_ROLE_SEQ

Hibernate: create table SFINX_CRITERIA (ID number(19,0) not null, CREATE_DATE timestamp not null, UPDATE_DATE timestamp not null, DELETED char(1 char), DESCRIPTION varchar2(1000 char), NAME varchar2(255 char) not null, CRITERIA_TYPE_ID number(19,0) not null, primary key (ID), unique (NAME))
Hibernate: create table SFINX_CRITERIA_TYPE (ID number(19,0) not null, NAME varchar2(255 char) not null unique, primary key (ID), unique (NAME))
Hibernate: create table SFINX_CRITERIA_TYPE_ITEM (ID number(19,0) not null, VALUE varchar2(255 char) not null, CRITERIA_TYPE_ID number(19,0) not null, primary key (ID), unique (CRITERIA_TYPE_ID, VALUE))
Hibernate: create table SFINX_DEPARTMENT (ID number(19,0) not null, NAME varchar2(255 char) not null, primary key (ID), unique (NAME))
Hibernate: create table SFINX_EMPLOYEE (ID number(19,0) not null, ARCHIVED char(1 char), EMAIL varchar2(255 char), FIRST_NAME varchar2(255 char), LAST_NAME varchar2(255 char), LOGIN varchar2(255 char) not null unique, DEPARTMENT_ID number(19,0), primary key (ID), unique (LOGIN))
Hibernate: create table SFINX_EMPLOYEE_EVALUATION (ID number(19,0) not null, CREATE_DATE timestamp not null, UPDATE_DATE timestamp not null, EMPLOYEE_ID number(19,0) not null, EVALUATION_ID number(19,0) not null, PROJECT_ID number(19,0) not null, primary key (ID), unique (EVALUATION_ID, EMPLOYEE_ID, PROJECT_ID))
Hibernate: create table SFINX_EMPLOYEE_SYSTEM_ROLE (EMPLOYEE_ID number(19,0) not null, SYSTEM_ROLE_ID number(19,0) not null)
Hibernate: create table SFINX_EVALUATION (ID number(19,0) not null, CREATE_DATE timestamp not null, UPDATE_DATE timestamp not null, CLOSURE_DATE timestamp, DELETED char(1 char), DESCRIPTION varchar2(1000 char), END_DATE timestamp, NAME varchar2(255 char) not null, START_DATE timestamp, STATUS varchar2(255 char), MASTER_ID number(19,0) not null, primary key (ID), unique (NAME))
Hibernate: create table SFINX_EVALUATION_CRITERIA (ID number(19,0) not null, CRITERIA_ID number(19,0) not null, EVALUATION_ID number(19,0) not null, primary key (ID), unique (CRITERIA_ID, EVALUATION_ID))
Hibernate: create table SFINX_EVALUATION_MANAGER (EVALUATION_ID number(19,0) not null, MANAGER_ID number(19,0) not null)
Hibernate: create table SFINX_EVALUATION_VIEWER (EVALUATION_ID number(19,0) not null, VIEWER_ID number(19,0) not null)
Hibernate: create table SFINX_FEEDBACK (ID number(19,0) not null, CREATE_DATE timestamp not null, UPDATE_DATE timestamp not null, COMMENTS varchar2(1000 char), RELEASED char(1 char), VALUE varchar2(255 char), EMPLOYEE_EVALUATION_ID number(19,0) not null, EMPLOYEE_ID number(19,0) not null, EVALUATION_CRITERIA_ID number(19,0) not null, primary key (ID), unique (EMPLOYEE_ID, EMPLOYEE_EVALUATION_ID, EVALUATION_CRITERIA_ID))
Hibernate: create table SFINX_IMPROVEMENT_PROPOSAL (ID number(19,0) not null, PROPOSAL varchar2(1000 char) not null, EMPLOYEE_ID number(19,0) not null, primary key (ID))
Hibernate: create table SFINX_PROJECT (ID number(19,0) not null, CLIENT_NAME varchar2(255 char), DELETED char(1 char), END_DATE timestamp not null, NAME varchar2(255 char) not null, START_DATE timestamp not null, WBS varchar2(255 char), primary key (ID), unique (NAME))
Hibernate: create table SFINX_PROJECT_EMPLOYEE (ID number(19,0) not null, EMPLOYEE_ID number(19,0) not null, PROJECT_ID number(19,0), ROLE_ID number(19,0) not null, primary key (ID), unique (EMPLOYEE_ID, PROJECT_ID))
Hibernate: create table SFINX_ROLE (ID number(19,0) not null, DELETED char(1 char), NAME varchar2(255 char), primary key (ID), unique (NAME))
Hibernate: create table SFINX_SYSTEM_ROLE (ID number(19,0) not null, DELETED char(1 char), NAME varchar2(255 char) not null, primary key (ID), unique (NAME))

Hibernate: alter table SFINX_CRITERIA add constraint FKA3B6A81EED06FF7E foreign key (CRITERIA_TYPE_ID) references SFINX_CRITERIA_TYPE
Hibernate: alter table SFINX_CRITERIA_TYPE_ITEM add constraint FKEE5DAE17ED06FF7E foreign key (CRITERIA_TYPE_ID) references SFINX_CRITERIA_TYPE
Hibernate: alter table SFINX_EMPLOYEE add constraint FK767FAF6D15CF1A9F foreign key (DEPARTMENT_ID) references SFINX_DEPARTMENT
Hibernate: alter table SFINX_EMPLOYEE_EVALUATION add constraint FK1BC4A34ECDBE9A5F foreign key (EVALUATION_ID) references SFINX_EVALUATION
Hibernate: alter table SFINX_EMPLOYEE_EVALUATION add constraint FK1BC4A34EE55C6715 foreign key (PROJECT_ID) references SFINX_PROJECT
Hibernate: alter table SFINX_EMPLOYEE_EVALUATION add constraint FK1BC4A34EB756525F foreign key (EMPLOYEE_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_EMPLOYEE_SYSTEM_ROLE add constraint FKD0BCA2B4500008DE foreign key (SYSTEM_ROLE_ID) references SFINX_SYSTEM_ROLE
Hibernate: alter table SFINX_EMPLOYEE_SYSTEM_ROLE add constraint FKD0BCA2B4B756525F foreign key (EMPLOYEE_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_EVALUATION add constraint FKFE79983B8D73022B foreign key (MASTER_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_EVALUATION_CRITERIA add constraint FKCA237AE3CDBE9A5F foreign key (EVALUATION_ID) references SFINX_EVALUATION
Hibernate: alter table SFINX_EVALUATION_CRITERIA add constraint FKCA237AE394A3C8BF foreign key (CRITERIA_ID) references SFINX_CRITERIA
Hibernate: alter table SFINX_EVALUATION_MANAGER add constraint FK2C4B6F89CDBE9A5F foreign key (EVALUATION_ID) references SFINX_EVALUATION
Hibernate: alter table SFINX_EVALUATION_MANAGER add constraint FK2C4B6F8915931500 foreign key (MANAGER_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_EVALUATION_VIEWER add constraint FK5346E296CDBE9A5F foreign key (EVALUATION_ID) references SFINX_EVALUATION
Hibernate: alter table SFINX_EVALUATION_VIEWER add constraint FK5346E296236B9C7B foreign key (VIEWER_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_FEEDBACK add constraint FK23F2B44486766958 foreign key (EVALUATION_CRITERIA_ID) references SFINX_EVALUATION_CRITERIA
Hibernate: alter table SFINX_FEEDBACK add constraint FK23F2B444B756525F foreign key (EMPLOYEE_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_FEEDBACK add constraint FK23F2B444CE47D6DC foreign key (EMPLOYEE_EVALUATION_ID) references SFINX_EMPLOYEE_EVALUATION
Hibernate: alter table SFINX_IMPROVEMENT_PROPOSAL add constraint FK49CA2A9AB756525F foreign key (EMPLOYEE_ID) references SFINX_EMPLOYEE
Hibernate: alter table SFINX_PROJECT_EMPLOYEE add constraint FKE09FA2F3E55C6715 foreign key (PROJECT_ID) references SFINX_PROJECT
Hibernate: alter table SFINX_PROJECT_EMPLOYEE add constraint FKE09FA2F3BBCC17DF foreign key (ROLE_ID) references SFINX_ROLE
Hibernate: alter table SFINX_PROJECT_EMPLOYEE add constraint FKE09FA2F3B756525F foreign key (EMPLOYEE_ID) references SFINX_EMPLOYEE

Hibernate: create sequence SFINX_CRITERIA_SEQ
Hibernate: create sequence SFINX_CRITERIA_TYPE_ITEM_SEQ
Hibernate: create sequence SFINX_CRITERIA_TYPE_SEQ
Hibernate: create sequence SFINX_DEPARTMENT_SEQ
Hibernate: create sequence SFINX_EMPLOYEE_EVALUATION_SEQ
Hibernate: create sequence SFINX_EMPLOYEE_SEQ
Hibernate: create sequence SFINX_EVALUATION_CRITERIA_SEQ
Hibernate: create sequence SFINX_EVALUATION_SEQ
Hibernate: create sequence SFINX_FEEDBACK_SEQ
Hibernate: create sequence SFINX_IMPROVEMENT_PROPOSAL_SEQ
Hibernate: create sequence SFINX_PROJECT_EMPLOYEE_SEQ
Hibernate: create sequence SFINX_PROJECT_SEQ
Hibernate: create sequence SFINX_ROLE_SEQ
Hibernate: create sequence SFINX_SYSTEM_ROLE_SEQ

Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.056 sec <<< FAILURE!
findByCriteriaIdAndEvaluationId(net.gdcw.sfinx.dao.EvaluationCriteriaDaoTest)  Time elapsed: 0.026 sec  <<< ERROR!
org.springframework.dao.InvalidDataAccessResourceUsageException: user lacks privilege or object not found: ROWNUM; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: user lacks privilege or object not found: ROWNUM
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:231)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:214)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy47.findByCriteriaIdAndEvaluationId(Unknown Source)
    at net.gdcw.sfinx.dao.EvaluationCriteriaDaoTest.findByCriteriaIdAndEvaluationId(EvaluationCriteriaDaoTest.java:45)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:81)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Caused by: org.hibernate.exception.SQLGrammarException: user lacks privilege or object not found: ROWNUM
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:83)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at com.sun.proxy.$Proxy57.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1720)
    at org.hibernate.loader.Loader.doQuery(Loader.java:828)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
    at org.hibernate.loader.Loader.doList(Loader.java:2447)
    at org.hibernate.loader.Loader.doList(Loader.java:2433)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263)
    at org.hibernate.loader.Loader.list(Loader.java:2258)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1161)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
    at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:280)
    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.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:360)
    at com.sun.proxy.$Proxy56.getSingleResult(Unknown Source)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.getSingleResult(AbstractJPAQuery.java:245)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult(AbstractJPAQuery.java:323)
    at com.mysema.query.jpa.impl.AbstractJPAQuery.uniqueResult(AbstractJPAQuery.java:308)
    at com.mysema.query.support.ProjectableQuery.singleResult(ProjectableQuery.java:150)
    at net.gdcw.sfinx.dao.EvaluationCriteriaDAOImpl.findByCriteriaIdAndEvaluationId(EvaluationCriteriaDAOImpl.java:40)
    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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    ... 39 more

Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ROWNUM
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    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.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
    ... 76 more

Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ROWNUM
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.ExpressionColumn.checkColumnsResolved(Unknown Source)
    at org.hsqldb.QueryExpression.resolve(Unknown Source)
    at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 83 more
    null

共有1个答案

葛永丰
2023-03-14

您在单元测试中使用HSQLDB,在生产中使用Oracle。

要使用Oracle方言运行HSQLDB,必须首先在HSQLDB上启用Oracle语法兼容模式:

SET DATABASE SQL SYNTAX ORA TRUE;

运行时错误很可能是由对查询结果大小施加的限制造成的。在Oracle中,这是通过使用pseudocolumn rownum来实现的。HSQLDB仅在兼容模式下理解ROWNUM。

 类似资料: