Question

I'm having a very strange problem with JPA and Java 8 functional programming.

I have a Student and Presentation class and their relationship is bidirectional. Everything worked fine in Java 7, but I just switched to Java 8.

This works (visible is private, has no setters):

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

This crashes:

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

Which gives this exception multiple times:

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)

I'm pretty sure the persistence.xml is configured correctly (because it works without Java 8) and all classes are included and have @Entity. It's also not the Student class, because if I comment that out, the error just gives another class.

What's causing this? Maybe it's also worth mentioning that I get a compile crash once a while and that they ask me to send the project to Oracle.

Was it helpful?

Solution

Think you'll find that current EclipseLink doesn't support Java 1.8 syntaxis; look at https://github.com/averri/jpa-lambda-integration-test

I use DataNucleus v4.0 for my projects and works for Java 1.8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top