0

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;

    ...
}
9
  • 1
    check what it is executing; it is likely trying to recreate an index that already exists and then assuming they are all there. I believe EclipseLink handles the indexes and constraints separately from the tables, and is treating it as an all or nothing. File a bug/feature to have this fixed. On Glassfish, they use EclipseLink to generate scripts, and then execute the scripts. This might work better for you, as the indexes would then be created independently, one by one, and so all get a chance to be recreated. Commented Mar 1, 2019 at 17:56
  • So, I checked ... I deleted all indexes and try to recreate them, but it didn't do anything (didn't even try to make a DB transaction) (with JBoss). I'll file a bug and hope it get fixed soon. Thanks! Commented Mar 4, 2019 at 8:44
  • I don't know what you mean when you say you deleted and tried recreating indexes. What is the SQL EclipseLink is generating? Commented Mar 4, 2019 at 15:33
  • I've added this line to see the generated SQL: <property name="eclipselink.ddl-generation.output-mode" value="both"/> <property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration_kernel.jdbc"/> Here is the result : (see next comment) Commented Mar 4, 2019 at 15:56
  • CREATE TABLE digit.Identity ((deleting this or comment is too long)) CREATE INDEX idxname ON digit.identity (lastname, firstname) CREATE INDEX IdxFirstname ON digit.Identity (Firstname) CREATE INDEX IdxLastname ON digit.Identity (Lastname) CREATE INDEX IdxId ON digit.Identity (Identity_Id) CREATE SEQUENCE digit.SEQ_Identity START WITH 500000 CREATE SEQUENCE digit.SEQ_Identity START WITH 500000 Commented Mar 4, 2019 at 15:59

1 Answer 1

1

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"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.