I'm testing (or trying to) my JPA/EJB classes against WildFly10 / H2 database using Arquillian. The primary key for an entity class is using GenerationType.TABLE
. The persistence-unit in /META-INF/persistence.xml
:
<persistence-unit name="test">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/H2DS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
<property name="javax.persistence.schema-generation.create-source" value="script" />
<property name="javax.persistence.schema-generation.create-script-source" value="META-INF/sql/create.sql" />
<property name="javax.persistence.sql-load-script-source" value="META-INF/sql/load_script.sql" />
<property name="javax.persistence.schema-generation.drop-source" value="script" />
<property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/sql/drop.sql" />
</properties>
</persistence-unit>
The problem is, the data that was supposed to be preloaded from load_script.sql is not committed by the time the test starts. I can see from logs the SQL statements to preload the test data, to update the "generator table", but I do not see any queries to the "generator table" to obtain a batch of primary keys. Then - no surprise - an attempt to add an entity ends up in constraint violation.
The question: how to make sure with Hibernate that the data preloaded from script is persisted before the tests take place?
Note 1: I had this issue with EclipseLink/Glassfish4, but that was remedied by both creating the schema and loading data from scripts (previously the schema was generated from entity classes).
Note 2: Without preloading any data the tests run fine both on Glassgish4 and WildFly10.