javahsqldbopenjpajboss-arquillianopenejb

Arquillian Entities with schema


I am setting up Arquillian with OpenEJB. I want to test a webservice with access to a database. I was able to setup everything with my own bean and entity for testing purposes.

Now I am adding all classes and dependencies and trying to start the test. But it fails to deploy, because my entities have an schema defined in its @Table annotation.

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 {

last part of 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

I already tried adding the schema via @CreateShema annotation and adding a lot of different properties, but nothing solved the problem.
Arquillian starts a HSQL Database.


Solution

  • I ended up using an Arquillian extension like this:
    https://github.com/arquillian/arquillian-examples/tree/master/arquillian-lifecycle-extension-tutorial

    I start a H2 database before the deployment, create the required schemata and shut it down after undeployment.