Search code examples
javamavenjakarta-eejbosseclipselink

JBoss Eclipselink not creating indexes in postgresql on create-tables / create-or-extend-tables


I am working on a maven project using JBoss and eclipselink and I have problems creating indexes (via JPA) in postgresql with a JBoss server.

The tables and indexes are getting created when the ddl-generation property is set to "drop-and-create-tables"

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

But when i set this property to either "create-or-extend-tables" or "create-tables", the tables are getting created and updated, but my indexes are NOT.

<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>

I have tried running the same code on a Glassfish server, and on a Glassfish, the indexes ARE GETTING CREATED. So the problem only occurs when I'm running a JBoss server (ultimately, I want my project to run on a JBoss server).

Here is my 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="Request_PU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/gid_postges</jta-data-source>
<class>be.uclouvain.digit.request.models.LogRequest</class>
<class>be.uclouvain.digit.request.models.LogStatus</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
  <property name="eclipselink.logging.level" value="FINE"/>
  <property name="eclipselink.logging.level.sql" value="FINE"/>
  <property name="eclipselink.logging.parameters" value="true"/>
  <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>

  <property name="eclipselink.deploy-on-startup" value="true"/>
</properties>

And here is an Entity exemple

@Entity
@Table(name = "Identity", schema = "digit")
@SequenceGenerator(name = "SEQ_Identity", sequenceName = "SEQ_Identity", schema = "digit", allocationSize = 1, initialValue = 500000)
@EntityListeners(IdentityListener.class)
@Index(columnNames = {"Lastname","Firstname"},name = "IdxName")
public class Identity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_Identity")
    @Index
    @Column(name = "Identity_Id")
    private BigInteger identityId;
    @NotNull
    @Size(max = 50)
    @Index
    @Column(name = "Lastname", nullable = false, length = 50)
    private String lastname;
    @NotNull
    @Size(max = 50)
    @Column(name = "Firstname", nullable = false, length = 50)
    private String firstname;

    ...
}

Solution

  • Alright so I've manage to work around the issue to fix the problem by simply create my tables with eclipselink and then, save the script and then execute that script as a check, so if the indexes were not created with the tables, they would then be created by running the script.

    Not great, but it'll work while waiting for a better solution.

    My new persistence.xml looks like this :

      <property name="eclipselink.logging.parameters" value="true"/>
      <property name="eclipselink.logging.level.sql" value="FINEST" />
      <property name="eclipselink.logging.level" value="FINEST" />
      <property name="eclipselink.logging.level.cache" value="FINEST" />
    
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    
      <property name="javax.persistence.schema-generation.scripts.action" value="create" />
      <property name="javax.persistence.schema-generation.scripts.create-target" value="../../NetBeansProjects/digit/src/Digit-kernel/src/main/resources/createKernel.sql"/>
      <property name="javax.persistence.schema-generation.scripts.drop-target" value="../../NetBeansProjects/digit/src/Digit-kernel/src/main/resources/dropKernel.sql"/>
      <property name="javax.persistence.sql-load-script-source" value="createKernel.sql"/>
      <property name="eclipselink.deploy-on-startup" value="true"/>