【问题标题】:Functional operators causes JPA to crash? (Bug?)函数式运算符导致 JPA 崩溃? (漏洞?)
【发布时间】:2014-06-30 22:18:08
【问题描述】:

我在使用 JPA 和 Java 8 函数式编程时遇到了一个非常奇怪的问题。

我有一个 StudentPresentation 类,它们的关系是双向的。在 Java 7 中一切正常,但我刚刚切换到 Java 8。

这个有效(可见是私有的,没有设置器):

public static void setAllVisible(boolean visible) {
    for (Presentation presentation : new PresentationRepository().findAll()) {
        presentation.visible = visible;
    }
}

崩溃

public static void setAllVisible(boolean visible) {
    new PresentationRepository().findAll().forEach(x -> x.visible = visible);        
    //same for new PresentationRepository().findAll().stream().forEach(x -> x.visible = visible);
}

多次给出此异常:

Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@4554617c
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [BachelorproefPU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class models.users.Student] uses a non-entity [class models.planning.Presentation] as target entity in the relationship attribute [field presentation].
    at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
    at persistence.JPAEntityManager.getEntityManagerFactory(JPAEntityManager.java:45)
    at models.repositories.Repository.<init>(Repository.java:23)
    at models.repositories.UserRepository.<init>(UserRepository.java:15)
    at main.DbInitializer.<init>(DbInitializer.java:27)
    at main.DbInitializer.main(DbInitializer.java:23)

我很确定persistence.xml 配置正确(因为它可以在没有Java 8 的情况下工作)并且所有类都包含在内并具有@Entity。它也不是 Student 类,因为如果我将其注释掉,错误只会给出另一个类。

这是什么原因造成的?也许还值得一提的是,我偶尔会遇到编译崩溃,他们要求我将项目发送给 Oracle。

【问题讨论】:

    标签: jpa functional-programming eclipselink java-8


    【解决方案1】:

    您会发现当前的 EclipseLink 不支持 Java 1.8 语法;看着 https://github.com/averri/jpa-lambda-integration-test

    我将 DataNucleus v4.0 用于我的项目并适用于 Java 1.8

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 2013-07-04
      • 2021-05-18
      相关资源
      最近更新 更多