我正在使用io.github.divinespear:jpa-schema-maven-plugin:0.1.12插件生成我的sql脚本。过去效果不错,但最近已停止工作。特定的错误消息是:
[ERROR] Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: java.net.URLClassLoader@28a6301f
[ERROR] Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
[ERROR] Exception Description: Predeployment of PersistenceUnit [userService] failed.
[ERROR] Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
[ERROR] Exception Description: Entity class [class my.firm.integration.sp.usermanager.entity.PermissionEntity] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations the
n make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
我的某些实体使用@MappedSuperclass,但是此类未定义主键。我不会混合访问类型。
因为我已经在这个项目上工作了一段时间,但是很少添加新实体或更改现有实体,所以我无法确定插件停止工作的时间。回到以前的提交并没有改变结果,在这一点上,我不得不假设它是另外一回事。
以下是示例实体,相关代码和配置:
PermissionEntity.java:
package my.firm.integration.sp.usermanager.entity;
import my.firm.integration.sp.userauthentication.dto.PermissionDTO;
import lombok.Data;
import javax.persistence.*;
import java.util.Map;
import java.util.stream.Collectors;
@Entity
@Data
@Table(name = "PERMISSIONS")
public class PermissionEntity extends VersionedEntity {
@Id
@GeneratedValue
@Column(name = "ID")
private String id;
@Column(name = "PERMISSION_ID")
private String permissionId;
@ManyToMany(cascade = CascadeType.ALL)
private Map<String, PermissionAttributeValueEntity> permissions;
public PermissionDTO toDTO() {
PermissionDTO dto = new PermissionDTO();
dto.setId(id);
dto.setPermissionDefinitionId(permissionId);
dto.setFields(permissions
.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey, entry -> entry.getValue().toDTO())));
return dto;
}
}
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="userService" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.jdbc.batch-writing" value="jdbc"/>
<property name="javax.persistence.schema-generation.scripts.action" value="none"/>
<property name="eclipselink.ddl-generation.index-foreign-keys" value="true"/>
<!-- <property name="javax.persistence.schema-generation.database.action" value="create"/> -->
</properties>
</persistence-unit>
</persistence>
eclipselink-orm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.6"
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_6.xsd">
<persistence-unit-metadata>
<persistence-unit-defaults>
<tenant-discriminator-column name="TENANT_ID" column-definition="VARCHAR(64) NOT NULL"
context-property="eclipselink.tenant-id" length="64" />
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity class="my.firm.integration.sp.usermanager.entity.UserEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
<entity class="my.firm.integration.sp.usermanager.entity.RoleEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
<entity class="my.firm.integration.sp.usermanager.entity.PermissionEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
<entity class="my.firm.integration.sp.usermanager.entity.PermissionAttributeValueEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
<entity class="my.firm.integration.sp.usermanager.entity.UserLockoutEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
<entity class="my.firm.integration.sp.usermanager.entity.IpLockoutEntity">
<multitenant type="SINGLE_TABLE">
</multitenant>
</entity>
</entity-mappings>
我pom.xml中配置的插件:
<plugin>
<groupId>io.github.divinespear</groupId>
<artifactId>jpa-schema-maven-plugin</artifactId>
<version>0.1.12</version>
<configuration>
<scriptAction>create</scriptAction>
<dialect>dummy</dialect>
<databaseProductName>${database.productName}</databaseProductName>
<persistenceUnitName>userService</persistenceUnitName>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
</plugin>
当我使用以下maven命令:mvn -Ddatabase.productName="Microsoft SQL Server" jpa-schema:generate
时,我希望将架构放置在target/generated-schema
文件夹中,但是会发生上述错误。