3

我正在使用 h2 为使用 Eclipselink、Arquillian 和 Weblogic 12.1.1 的应用程序设置集成测试

这是我的实体:

@Entity
@Table(name = "AFIS_REQUEST")
public class Request implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "requestSEQ")
    @SequenceGenerator(name = "requestSEQ", sequenceName = "REQUEST_ID_SEQ", allocationSize = 1)
    @Column(name = "ID")
    private Long id;
...
}

这是我的persistence.xml

<persistence-unit name="myPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/arquillian</jta-data-source>
        <class>com.my.Request</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <validation-mode>NONE</validation-mode>
        <properties>
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>            
            <property name="eclipselink.logging.level.sql" value="FINEST"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
        </properties>
    </persistence-unit>

这是我在 Weblogic 数据源中指定的 JDBC URL 和 Driver 类:

  • jdbc:h2:文件:目标/数据库/h2/db
  • org.h2.jdbcx.JdbcDataSource

但是当我开始测试时,我得到以下异常:

<Dec 3, 2012 3:58:23 PM IRST> <Warning> <EclipseLink> <BEA-2005000> <2012-12-03 15:58:23.217--ServerSession(16406343)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: Sequence "REQUEST_ID_SEQ" not found; SQL statement:
CALL NEXT VALUE FOR REQUEST_ID_SEQ [90036-166]
Error Code: 90036
Call: CALL NEXT VALUE FOR REQUEST_ID_SEQ
Query: ValueReadQuery(sql="CALL NEXT VALUE FOR REQUEST_ID_SEQ")> 

因为我希望在开始测试时创建表,并在完成分配drop-and-create-tableseclipselink.ddl-generation属性的测试时删除表。但似乎 Table 已生成,但它的序列不是由 Eclipselink 创建的。

h2 是否支持生成序列?还是我缺少任何配置?

编辑: 我检查了生成的 DDL,它显示创建序列语句已生成。

CREATE TABLE REQUEST (ID BIGINT NOT NULL, ... , PRIMARY KEY (ID))
CREATE SEQUENCE REQUEST_ID_SEQ START WITH 1

然后我使用 H2 Web 控制台连接到生成的数据库,看到生成了序列,我可以在CALL NEXT VALUE FOR REQUEST_ID_SEQ那里成功执行!

那么为什么 Eclipselink 抱怨它!?Sequence "REQUEST_ID_SEQ" not found;

4

1 回答 1

4

我遇到了同样的问题,我设法让它工作,只需将此行添加到您的持久性文件中:

<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>

它必须是 的第一个属性<properties>

请注意,您仍然会收到警告。

我在这里找到了解决方案

于 2014-06-16T15:35:14.580 回答