JBoss Eclipselink不在Postgresql中的create-tables / create-or-extend-tables上创建索引

时间:2019-03-01 10:17:08

标签: java maven java-ee jboss eclipselink

我正在使用JBoss和eclipselink进行Maven项目,并且在通过JBoss服务器在PostgreSQL中创建索引(通过JPA)时遇到问题。

将ddl-generation属性设置为“ drop-and-create-tables”时,将创建表和索引

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

但是当我将此属性设置为“ create-or-extend-tables”或“ create-tables”时,正在创建和更新表,但是我的索引不是。

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

我尝试在Glassfish服务器上运行相同的代码,并且在Glassfish上,索引正在创建。因此,仅当我在运行JBoss服务器时才会出现此问题(最终,我希望我的项目在JBoss服务器上运行)。

这是我的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>

这是一个实体示例

@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;

    ...
}

1 个答案:

答案 0 :(得分:0)

好吧,所以我设法通过简单地使用eclipselink创建我的表来解决此问题,然后保存脚本,然后执行该脚本作为检查,因此,如果索引不是使用表创建的,然后可以通过运行脚本来创建它们。

不太好,但是可以在等待更好的解决方案时使用。

我的新persistence.xml看起来像这样:

  <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"/>