【发布时间】:2016-01-11 07:06:31
【问题描述】:
我的应用程序在 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)
...
相反,当我在使用 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
}
REST API:
@POST
public Response create(Throw entity) {
em.persist(entity);
return Response.created(URI.create("...")).build();
}
我认为 Eclipselink 在解组我的 json 时存在问题。我需要任何额外的注释吗?
【问题讨论】:
-
加入继承将默认使用“类型”字段来确定要使用的实体类,就像 json/xml 编组一样。您有一个类型字段,但用无法转换为类的“Miss”填充它。请参阅 stackoverflow.com/questions/8942945/… 了解自定义策略或 eclipse.org/eclipselink/documentation/2.4/moxy/… 如果您可以更改正在发布的 JSON
-
我将属性重命名为 throwingType 这解决了我的问题。您能否将您的评论发布为答案,以便我将其标记为答案。
-
有什么解释为什么 EclipseLink 失败而 Hibernate 没有?
-
Hibernate 在数据库中使用连接继承时不会使用类型字段,因为它可以使用查询连接机制。 EclipseLink 确实使用该类型,因为它更有效地过滤掉不需要的连接,并且还必须与无法连接的 JSON/XML 抗衡。
标签: java rest jpa glassfish eclipselink