EclipseLink:实体未加载 [英] EclipseLink: Entities not loaded

查看:140
本文介绍了EclipseLink:实体未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JPA项目,由于遇到了 EclipseLink的错误429992 。有了新版本后,我不再能够执行我的应用程序-EclipseLink引发类似于以下的异常(下面示例中的简短变体):

  [EL警告]:元模型:2018-06-20 22:38:14.1--Thread(Thread [main,5,main])-元模型类型的集合为空。在实体搜索Java SE和某些Java EE容器管理的持久性单元期间,可能找不到模型类。请使用< class>验证是否在persistence.xml中引用了您的实体类。元素或全局< exclude-unlist-classes> false< / exclude-unlisted-classes>元素
[...]

线程主中的异常java.lang.IllegalArgumentException:对象:Artifact @ 17d919b6不是已知的实体类型。在org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4324)处的
在org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:593)处的

在Main.main(Main.java:12)

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



我已经用下面的最小设置重现了此行为。 / p>

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



您是否能够重现此错误?



据我所知,则Entity-class在persistence.xml中列出,并用 @Entity 进行注释,但EclipseLink不会加载。清理项目甚至创建一个新项目都不能解决问题。



您有一个主意,我的错误可能是什么?我是否缺少有关JPA 2.2 / EclipseLink 2.7.1用法的基本要点?



感谢您的任何提示或评论!






main 中的方法

  EntityManagerFactory实体管理器工厂= Persistence.createEntityManagerFactory( Example); 
EntityManager实体管理器=实体管理器工厂.createEntityManager();

entityManager.getTransaction()。begin();
Artifact工件= new Artifact();
entityManager.persist(artifact);
entityManager.getTransaction()。commit();

entityManager.close();
entityManagerFactory.close();

实体工件

  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,查询= SELECT a FROM Artifact a)
公共类Artifact {
private int id ;

@ Id
@ GeneratedValue(strategy = GenerationType.IDENTITY)
public int getId(){
返回this.id;
}

public void setId(int id){
this.id = id;
}
}

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-实例 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>工件< / class>

< properties>
<属性名称= javax.persistence.jdbc.driver value = org.h2.Driver />
<属性名称= javax.persistence.jdbc.url value = jdbc:h2:./ inventory; create = true />
<属性名称= javax.persistence.jdbc.user value = APP />
<属性名称= javax.persistence.jdbc.password value = APP />
<属性名称= eclipselink.logging.level值= FINEST />
<属性名称= eclipselink.ddl-generation value =创建或扩展表 />
<属性名称= eclipselink.ddl-generation.output-mode value =数据库 />
< / properties>
< / persistence-unit>
< / persistence>

pom.xml用于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>


解决方案

我也遇到了同样的问题。



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()为空。
更新后,我的所有实体均已成功加载



问题,并且可以从此链接


I have a JPA-Project, which I'm trying to update to JPA 2.2.0 and EclipseLink 5.7.1 since I ran into bug 429992 of EclipseLink. With the new versions in place, I'm not able to execute my application anymore – EclipseLink throws an exception similar to the following (Short variant from my example below):

[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)

Before the update, everything worked fine (besides the aforementioned bug), and also if I checkout an earlier commit, there are no problems.

I have reproduced this behaviour with the minimal setup attached below.

The project is compiled using Java SE 10, as IDE I'm using Eclipse, but in my project properties, I only have the option to select "Generic 2.1" as JPA-Platform. May this be an problem?

Are you able to reproduce this error?

As far as I can see, the Entity-class is listed in the persistence.xml and also annotated with @Entity, but not loaded by EclipseLink. Cleaning the project or even creating a new one does not solve the problem.

Do you have an idea, what my mistake might be? Am I missing any fundamental point about the usage of JPA 2.2/EclipseLink 2.7.1?

Thank you for any hints or comments!


main method in the main class:

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();

Entity 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;
    }
}

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="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 dependencies:

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

解决方案

I had the same problem too. finally, it was solved with an update in pom.xml.

Eclipselink 2.7.1 version has some bugs that fixed at newer versions.

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

to

 <version>2.7.5</version>

before the update, entities are not loaded and em.getMetamodel() was empty. after the update, all of my entities are loaded successfully

issues and the fixed bugs can be accessed from this link.

这篇关于EclipseLink:实体未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆