功能操作符导致JPA崩溃? (错误?)

时间:2014-05-13 09:47:03

标签: jpa functional-programming eclipselink java-8

我在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。

1 个答案:

答案 0 :(得分:1)

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

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