Java Eclipselink忽略具有lambda表达式的实体类

Java Eclipselink忽略具有lambda表达式的实体类,java,lambda,eclipselink,java-8,Java,Lambda,Eclipselink,Java 8,我正在用EclipseLink(2.5.1,也尝试了2.5.2-M1)构建一个java SE 8(oracle 1.8.0-b129)应用程序,并且有一个Entity类,尽管在persistence.xml文件中有正确的注释和引用,但EclipseLink只是忽略了它。日志中没有提到该类,也没有为其生成架构,等等。使用该实体会出现“抽象架构类型未知”错误 我想我终于找到了原因,并想与大家分享。显然,EclipseLink不喜欢带有lambda表达式的类。下面是一个简单的类,它再现了这个问题: @

我正在用EclipseLink(2.5.1,也尝试了2.5.2-M1)构建一个java SE 8(oracle 1.8.0-b129)应用程序,并且有一个Entity类,尽管在persistence.xml文件中有正确的注释和引用,但EclipseLink只是忽略了它。日志中没有提到该类,也没有为其生成架构,等等。使用该实体会出现“抽象架构类型未知”错误

我想我终于找到了原因,并想与大家分享。显然,EclipseLink不喜欢带有lambda表达式的类。下面是一个简单的类,它再现了这个问题:

@Entity
public class LambdaEntity {

    @Id
    private Integer id;

    public void theLambda() {
        Arrays.asList(1, 2, 3).stream().filter(m -> m == 2);
    }
}
lambda表达式甚至不必使用持久性属性,它在类中的简单存在就足够了。有人知道这是什么原因吗?我猜EclipeLink会阻塞生成的字节码,但我觉得奇怪的是它会默默地忽略这个类

如果您试图在与其他实体的关联中使用此实体,EclipseLink将给出一个错误,指出该实体未在
persistence.xml
文件中定义。stacktrace的一部分:

Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@3b9a45b3
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [hcm-test] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class com.senior.hcm.domain.organization.Workstation] uses a non-entity [class com.senior.hcm.domain.auth.UserRole] as target entity in the relationship attribute [field roles].
    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 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [hcm-test] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class com.senior.hcm.domain.organization.Workstation] uses a non-entity [class com.senior.hcm.domain.auth.UserRole] as target entity in the relationship attribute [field roles].
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
    at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
    ... 28 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [hcm-test] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class com.senior.hcm.domain.organization.Workstation] uses a non-entity [class com.senior.hcm.domain.auth.UserRole] as target entity in the relationship attribute [field roles].
    at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
    ... 32 more
Caused by: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class com.senior.hcm.domain.organization.Workstation] uses a non-entity [class com.senior.hcm.domain.auth.UserRole] as target entity in the relationship attribute [field roles].
    at org.eclipse.persistence.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1378)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.getReferenceDescriptor(RelationshipAccessor.java:553)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.getOwningMapping(RelationshipAccessor.java:469)
    at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToManyAccessor.process(ManyToManyAccessor.java:149)
    at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processNonOwningRelationshipAccessors(MetadataProject.java:1566)
    at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage3(MetadataProject.java:1855)
    at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:580)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:585)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
    ... 30 more

正如Michael Jess(谢谢:)所建议的,这里有一个链接,指向解决此问题的。不幸的是,我还没有找到时间来测试已经在那里完成的工作,但它看起来很有希望。这个问题似乎不会持续太久。

经过一整天的调试和阅读教程,我认为我能够确定“Java 8功能”是您所描述的问题的症结所在。事实上,它实际上只是Lambda表达式——因此,您可以通过避免Lambda语法糖并在Java之前的8-way中定义过滤器来规避这些问题。为什么不通过链接您提交的相应文件来自己回答这个问题呢?答案似乎涵盖了你的问题;)我的天啊,我为此损失了5个小时的工作。我无法通过stacktrace找到您的问题,只是在我找到lambda表达式的问题后才找到它。我将编辑您的问题,以包括stacktrace,希望它能帮助某人。这是一个半天的工作,我不会看到任何更新版本的EclipseLink解决了这个问题。但是当我想在我的开发机器上部署一个功能齐全的应用程序到AWS Elastic Beanstalk(使用旧版本)时,仍然发现这很有用,并遇到了这个问题。谢谢