具有模式的Arquillian实体

时间:2017-02-01 10:05:03

标签: java hsqldb openjpa jboss-arquillian openejb

我正在使用OpenEJB设置Arquillian。我想测试一个可以访问数据库的Web服务。我能够使用自己的bean和实体设置所有内容以进行测试。

现在我正在添加所有类和依赖项并尝试启动测试。但它无法部署,因为我的实体在其@Table注释中定义了一个模式。

arquillian.xml

<arquillian xmlns="http://jboss.org/schema/arquillian"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
    <engine>
        <property name="deploymentExportPath">target/deployments</property>
    </engine>

    <container default="true" qualifier="openejb-embedded-4">
        <configuration>
            <property name="properties">
                testDatabase = new://Resource?type=DataSource
            </property>
        </configuration>
    </container>
</arquillian>

的persistence.xml

<?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="newejb" transaction-type="JTA">
        <jta-data-source>testDatabase</jta-data-source>
        <class>[...].AuftragsHistorie</class>
        <properties>
            <property name="openejb.jpa.init-entitymanager" value="true" />
            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
        </properties>
    </persistence-unit>
</persistence>

AuftragsHistorie.java

@Entity(name = "AuftragsHistorie")
@SequenceGenerator(
    name = "AUFTRAGSHISTORY_GENERATOR",
    sequenceName = "SEQ_T_PUB_INET_DAF",
    allocationSize = 1
)
@Table(
    name = "T_PUB_INET_DAF",
    schema = "DATA_SCHEMA"
)
public class AuftragsHistorie implements Serializable {

stacktrace的最后一部分

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: invalid schema name: DATA_SCHEMA in statement [CREATE TABLE DATA_SCHEMA.T_PUB_INET_DAF (ID BIGINT NOT NULL, AUFTRAGS_ART_NAME VARCHAR(255) NOT NULL, ERF_DATUM TIMESTAMP NOT NULL, VERS_NR VARCHAR(255) NOT NULL, PRIMARY KEY (ID))] {stmnt 2112059634 CREATE TABLE DATA_SCHEMA.T_PUB_INET_DAF (ID BIGINT NOT NULL, AUFTRAGS_ART_NAME VARCHAR(255) NOT NULL, ERF_DATUM TIMESTAMP NOT NULL, VERS_NR VARCHAR(255) NOT NULL, PRIMARY KEY (ID))} [code=-4850, state=3F000]
    at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:218)
    at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:202)
    at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:58)
    at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingStatement.executeUpdate(LoggingConnectionDecorator.java:913)
    at org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:118)
    at org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1231)
    at org.apache.openjpa.jdbc.schema.SchemaTool.createTable(SchemaTool.java:976)
    at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:552)
    at org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:364)
    at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:341)
    at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:505)
    ... 109 more

我已经尝试通过@CreateShema注释添加模式并添加了许多不同的属性,但没有解决问题。
Arquillian启动了HSQL数据库。

1 个答案:

答案 0 :(得分:0)

我最终使用了这样的Arquillian扩展:
https://github.com/arquillian/arquillian-examples/tree/master/arquillian-lifecycle-extension-tutorial

我在部署之前启动H2数据库,创建所需的模式并在取消部署后将其关闭。