JBoss Eclipselink 没有在 postgresql 中的创建表/创建或扩展表上创建索引
JBoss Eclipselink not creating indexes in postgresql on create-tables / create-or-extend-tables
我正在使用 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;
...
}
好的,所以我设法解决了这个问题,只需使用 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"/>
我正在使用 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;
...
}
好的,所以我设法解决了这个问题,只需使用 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"/>