EclipseLink:未加载的实体



我有一个JPA项目,我正在尝试将其更新到JPA 2.2.0和EclipseLink 5.7.1,因为我遇到了EclipseLink的错误429992。有了新版本,我将无法再执行我的应用程序 – EclipseLink 抛出类似于以下内容的异常(下面示例的简短变体(:

[EL Warning]: metamodel: 2018-06-20 22:38:14.1--Thread(Thread[main,5,main])--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units.  Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
[...]
Exception in thread "main" java.lang.IllegalArgumentException: Object: Artifact@17d919b6 is not a known Entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4324)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:593)
at Main.main(Main.java:12)

在更新之前,一切正常(除了上述错误(,而且如果我签出较早的提交,也没有问题。

我使用下面附加的最小设置重现了这种行为。

该项目是使用 Java SE 10 编译的,因为 IDE 我使用的是 Eclipse,但在我的项目属性中,我只能选择"Generic 2.1"作为 JPA 平台。这可能是一个问题吗?

你能重现这个错误吗?

据我所知,实体类列在持久性中.xml并且还用@Entity注释,但未由 EclipseLink 加载。清理项目甚至创建一个新项目并不能解决问题。

你有想法吗,我的错误可能是什么?我是否错过了关于JPA 2.2/EclipseLink 2.7.1使用的任何基本点?

感谢您的任何提示或意见!


主类中的main方法:

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("Example");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
Artifact artifact = new Artifact();
entityManager.persist(artifact);
entityManager.getTransaction().commit();
entityManager.close();
entityManagerFactory.close();

实体Artifact

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
@Entity
@NamedQuery(name = "Artifact.findAll", query = "SELECT a FROM Artifact a")
public class Artifact {
private int id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
}

持久性.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="Example">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Artifact</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:./inventory;create=true"/>
<property name="javax.persistence.jdbc.user" value="APP"/>
<property name="javax.persistence.jdbc.password" value="APP"/>
<property name="eclipselink.logging.level" value="FINEST"/>            
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
</properties>
</persistence-unit>
</persistence>

pom.xml for Maven 依赖项:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JPATest</groupId>
<artifactId>JPATest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
</dependencies>
</project>

我也有同样的问题。 最后,它通过Pom.xml的更新解决了。

Eclipselink 2.7.1 版本有一些在较新版本中修复的错误。

<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.1</version>
</dependency>

<version>2.7.5</version>

在更新之前,实体不会加载,em.getMetamodel(( 为空。 更新后,我的所有实体都已成功加载

可以从此链接访问问题和修复的错误。

我有几乎相同的环境并遇到相同的问题。我几乎不敢说,但在日食中"项目/专家/更新项目......"帮助(到目前为止(。

相关内容

  • 没有找到相关文章

最新更新