枚举不是枚举映射的有效类型

时间:2014-10-29 22:14:43

标签: java maven jpa

当我尝试将我的webapp部署到Glassfish容器(静态shell和服务器)时,我对以下异常产生了一个真正的头脑。基本上,我有一个实体类,它具有以下属性:

    @Entity
    public class Anniversary implements Serializable, Comparable<Anniversary>
    {
     ...

        @Enumerated
        private AnniversaryType type;

     ....Rest of class
     }

它指的是声明如下的枚举类:

 public enum AnniversaryType

使用标准Maven项目在Netbeans 8.0中无需投诉即可构建程序,但在部署时会抛出以下异常:

Caused by: Exception [EclipseLink-7151] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):         org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class com.mycompany.anniversaries_final.AnniversaryType] for the   attribute [type] on the entity class [class com.mycompany.anniversaries_final.Anniversary] is not a     valid type for an enumerated mapping. The attribute must be defined as a Java enum.
at org.eclipse.persistence.exceptions.ValidationException.invalidTypeForEnumeratedAttribute(ValidationException.java:1125)
at org.eclipse.persistence.internal.jpa.metadata.converters.EnumeratedMetadata.process(EnumeratedMetadata.java:115)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processEnumerated(MappingAccessor.java:1684)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor.processEnumerated(BasicAccessor.java:467)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processMappingConverter(MappingAccessor.java:1769)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor.processMappingValueConverter(MappingAccessor.java:1796)
at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor.process(BasicAccessor.java:419)
at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.processMappingAccessors(MetadataDescriptor.java:1536)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processMappingAccessors(ClassAccessor.java:1648)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processMappingAccessors(EntityAccessor.java:1234)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:697)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1793)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:576)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:585)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
... 64 more

。我很困惑!我看了以下两个答案: JPA and enum typejaxws and EclipseLink refuses to use enums from lib如果类在一个单独的jar文件中,它们都提供答案,但在我的情况下它不是(据我所知)。我在应用程序的其他地方确实遇到了另一个问题,我将其用作地图键,并且必须按照https://bugs.eclipse.org/bugs/show_bug.cgi?id=364922明确命名表和键值。

我完全被难过......任何帮助都会非常感激!

1 个答案:

答案 0 :(得分:4)

固定!问题是由枚举类中的以下行引起的:

return Arrays.asList(values()).stream().filter(type -> {
          return type.isCultural();
       }).collect(Collectors.toList());

我似乎遇到了在实体类中使用流的问题;当我使用它们时,它们似乎会引起各种明显不相关的例外。我已经向Glassfish提交了一份bug报告并等待他们的回复......