0

我一直在尝试获得使用 openEJB 对项目进行单元测试的设置。我从现有项目中复制了大部分配置,该项目使用 hibernate-entitymanager 版本 3.3.2.GA ,但新项目使用版本 3.4.0.GA。当我指定实体管理器的 3.3.2.GA 版本时,我的单元测试有效,但在使用 3.4.0.GA 时无效

这是我与单元测试有关的 pom 设置:

        <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>javaee-api</artifactId>
        <version>5.0-2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-server</artifactId>
        <version>3.1.1</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>org.apache.openjpa</artifactId>
                <groupId>openjpa</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>3.3.2.GA</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
</dependencies>

我试图提高 openejb 服务器的版本号,但我的堆栈跟踪中不断出现以下异常:

    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:616)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:158)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:141)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:122)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:221)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:174)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281)
... 30 more
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:88)
... 43 more
Caused by: java.sql.SQLException: Column not found: ROWNUM in statement [select * from ( select user0_.id as id4_, user0_.MOBILE as MOBILE2_4_, user0_.CHANGED_BY as CHANGED3_4_, user0_.CHANGED_ON as CHANGED4_4_, user0_.PASSWORD_ANSWER as PASSWORD5_4_, user0_.PASSWORD_QUESTION as PASSWORD6_4_, user0_.REG_KEY as REG_KEY7_4_, user0_.USER_NAME as USER8_4_, user0_.VERSION as VERSION4_ from USER user0_ where user0_.USER_NAME=? ) where rownum <= ?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:250)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:250)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
... 51 more

这看起来像是 Hibernate 和 openEJB 之间的依赖问题,我只是不确定要使用哪个版本的 openejb。

这是查询:

"SELECT u FROM User u WHERE u.name = :name"
4

0 回答 0