Database creation not working in eclipselink with glassfish 4 and Postgres

I want to create a database based on Entities. Configuration:

  • Glassfish: GlassFish Server Open Source Edition 4.1 (Build 13)
  • Eclipselink: eclipse save services - 2.5.2.v20140319-9ad6abd (ships with sea fish)
  • Database: PostgreSQL Version: 9.4.2
  • Driver: PostgreSQL Native Driver Version: PostgreSQL 9.4 JDBC4.1 (Build 1201)

From the moment eclipselink starts creating the database, I see the following log entries after you have set many log options:

  • SELECT ID FROM table_name WHERE ID <> ID
  • SELECT 1

This is repeated 4-5 times. The first request gives the following obvious postgres error:

org.postgresql.util.PSQLException: ERROR: relation "table_name" does not exist Position: 16

As a result, the following queries give the following error:

org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands are ignored until the end of the transaction block

After that, eclipselink keeps creating tables:

CREATE TABLE table_name (ID BIGINT NOT NULL, PRIMARY KEY (ID))

But produces the same error.

For some reason, the creation of the database happens in a transaction. I found the original code responsible, but I can't seem to figure out how to start a transaction. I can give more details, but maybe someone can already help now.

Edit: 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="h ttp://java.sun.com/xml/ns/persistence    
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="AntennasOperatingSystemServerPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>MyDatabase</non-jta-data-source>
        <class>... bunch of classes ... </class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="eclipselink.logging.level" value="ALL"/>
            <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
            <property name="eclipselink.deploy-on-startup" value="true"/>
            <property name="eclipselink.ddl-generation.output-mode" value="database"/>
            <property name="eclipselink.logging.level.sql" value="FINEST"/>
            <property name="eclipselink.ddl-generation" value="create-tables"/>
            <property name="eclipselink.target-database" value="PostgreSQL" />
        </properties>
    </persistence-unit>
</persistence>

      

+3


source to share


2 answers


Have you tried setting the property eclipselink.target-database

to PostgreSQL

or org.eclipse.persistence.platform.database.PostgreSQLPlatform

?



Please share the persistence.xml file if that didn't fix the problem.

0


source


I did something similar a while ago. The following configuration works well.

<persistence-unit name="EjemploJpaPU" transaction-type="RESOURCE_LOCAL">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
  <exclude-unlisted-classes>false</exclude-unlisted-classes>
  <properties>
    <property name="javax.persistence.jdbc.url" 
              value="jdbc:derby://localhost:1527/example"/>
    <property name="javax.persistence.jdbc.driver" 
              value="org.apache.derby.jdbc.ClientDriver"/>
    <property name="javax.persistence.jdbc.user" value="root"/>
    <property name="javax.persistence.jdbc.password" value="123"/>
    <property name="eclipselink.logging.level" value="ALL"/>
    <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
  </properties>
</persistence-unit>

      



Obviously, after creating tables, you need to change the property value eclipselink.ddl-generation

to none

.

NOTE. The database was Derby, but I also tried it with MySQL. I think it will work with PostgreSQL.

0


source







All Articles