EclipseLink:缺少类型的指示符字段值

amm*_*zon 5 java rest jpa glassfish eclipselink

我的应用程序在Payara上运行并提供REST API但是当我尝试使用POST请求创建对象时,我得到以下异常:

Exception [EclipseLink-43] (Eclipse Persistence Services - 2.6.0.payara-p1): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [Miss] of type [class java.lang.String].
Descriptor: XMLDescriptor(at.htl.handballinheritance.entity.Throw --> [DatabaseTable(event), DatabaseTable(dataObject)])
  at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:940)
  at org.eclipse.persistence.internal.oxm.QNameInheritancePolicy.classFromRow(QNameInheritancePolicy.java:278)
  ...
Run Code Online (Sandbox Code Playgroud)

完整的Stacktrace

相反,当我在使用Hibernate的Wildfly上执行程序时,一切都很好并且没有错误发生.

实体:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@XmlRootElement
public abstract class Event extends DataObject implements Serializable {
    ... 
}

@Entity
public class Throw extends Event implements Serializable {

    @Enumerated(EnumType.STRING)
    @NotNull
    private ThrowingType type;

    ...
}

public enum ThrowingType {
    Goal, Miss
}
Run Code Online (Sandbox Code Playgroud)

REST API:

@POST
public Response create(Throw entity) {
    em.persist(entity);
    return Response.created(URI.create("...")).build();
}
Run Code Online (Sandbox Code Playgroud)

我认为Eclipselink解决我的json问题.我还需要任何其他注释吗?

Chr*_*ris 6

默认情况下,连接继承将使用“类型”字段来确定要使用的实体类,就像 json/xml 编组一样。您有一个类型字段,但使用无法转换为类的“小姐”填充它。

如果您可以更改发布的 JSON,请参阅eclipselink/Moxy:基于自定义策略类型的继承和属性名称重载https://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm

JPA 中的类型字段在这里有些讨论http://www.coderanch.com/t/489497/ORM/databases/InheritanceType-JOINED-DiscriminatorColumn 和这里 https://en.wikibooks.org/wiki/Java_Persistence/Inheritance# No_class_discriminator_column_2


Ale*_*ade 6

如果使用名为"type"的字段,则会出现此错误.