Eclipselink忽略具有lambda表达式的实体类 [英] Eclipselink ignores entity classes with lambda expressions

查看:112
本文介绍了Eclipselink忽略具有lambda表达式的实体类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EclipseLink(2.5.1,也尝试过2.5.2-M1)构建一个java SE 8(oracle 1.8.0-b129)应用程序,并且有一个Entity类,它被EclipeLink忽略,尽管它是在persistence.xml文件中正确注释和引用。日志显示没有提及类,没有为它生成模式,等等。使用实体给出'抽象模式类型未知'错误。

I am building a java SE 8 (oracle 1.8.0-b129) application with EclipseLink (2.5.1, also tried 2.5.2-M1), and have an Entity class that is simply being ignored by EclipeLink, despite being correctly annotated and referenced in the persistence.xml file. The logs show no mention of the class, no schema gets generated for it, etc. Using the entity gives the 'The abstract schema type is unknown' error.

我想我终于找到了原因,并认为我会分享。显然,EclipseLink不喜欢带有lambda表达式的类。这是一个简单的类来重现问题:

I think I have finally tracked down the cause, and thought I would share. Apparently, EclipseLink does not like classes with lambda expressions. Here is a simple class that reproduces the problem:

@Entity
public class LambdaEntity {

    @Id
    private Integer id;

    public void theLambda() {
        Arrays.asList(1, 2, 3).stream().filter(m -> m == 2);
    }
}

lambda表达式甚至不必使用持久化属性,它在类中的简单存在就足够了。有谁知道这会导致什么?我猜测EclipeLink会对生成的字节码产生阻塞,但我发现很奇怪,它会默默地忽略该类。

The lambda expression does not even have to use a persistent property, its simple existence in the class is enough. Does anyone know what could cause this? I'm guessing that EclipeLink chokes on the generated bytecode, but I find it strange that it silently ignores the class.

如果你试图在一个关联中使用这个实体另外,EclipseLink会给出一个错误,指出该实体未在 persistence.xml 文件中定义。 stacktrace的一部分:

If you try to use this Entity in an association with other, EclipseLink will give an error saying that the entity is not defined at the persistence.xml file. Part of the 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的建议(谢谢:)),这是一个链接针对此问题的错误报告。不幸的是,我还没有时间来测试那里已经完成的工作,但它看起来很有希望。这个问题不应该存在很长时间,它会出现。

As suggested by Michael Jess (thank you :)), here is a link to the bug report for this problem. Unfortunately I have not found the time to test the work that has been done there yet, but it looks promising. This problem should not be around much longer, it appears.

这篇关于Eclipselink忽略具有lambda表达式的实体类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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