gpt4 book ai didi

java - Eclipselink 忽略带有 lambda 表达式的实体类

转载 作者:IT老高 更新时间:2023-10-28 20:54:14 25 4
gpt4 key购买 nike

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

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

@Entity
public class LambdaEntity {

@Id
private Integer id;

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

lambda 表达式甚至不必使用持久属性,它在类中的简单存在就足够了。有谁知道这可能是什么原因?我猜 EcipeLink 会阻塞生成的字节码,但奇怪的是它会默默地忽略该类。

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

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 的建议(谢谢 :)),这里是 bug report 的链接对于这个问题。不幸的是,我还没有时间来测试那里已经完成的工作,但它看起来很有希望。看来,这个问题应该不会持续太久了。

关于java - Eclipselink 忽略带有 lambda 表达式的实体类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22298061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com