Question

In a JPA project when using the postgresql driver the tables are auto generated. When i switch to the h2 database driver, I get errors, that the tables are not found. This let me assume, that the tables are not generated.

Postgresql Config

<persistence-unit name="postgresql" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>...</class>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1/example"/>
        <property name="javax.persistence.jdbc.password" value="example"/>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
        <property name="javax.persistence.jdbc.user" value="example"/>
        <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
    </properties>
</persistence-unit>

h2 config

<persistence-unit name="OntoJobTestDB" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>...</class>    
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
        <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
</persistence-unit>
Was it helpful?

Solution

It turned out, that the tables could not have been found, because they were never created. An early error caused by a @Converter annotation, which was postgresql specific prevented the creation of the tables.

My advice is to always double check the debug output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top