【问题标题】:EclipseLink: Missing class for indicator field value of typEclipseLink:类型的指标字段值缺少类
【发布时间】: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)
  ...

Full 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
}

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


【解决方案1】:

如果您使用名为“type”的字段,您将收到此错误。

【讨论】:

  • 这实际上是我的问题..救了我。
【解决方案2】:

默认情况下,联合继承将使用“类型”字段来确定要使用的实体类,就像 json/xml 编组一样。你有一个类型字段,但用“Miss”填充它,它不能转换为一个类。

请参阅 eclipselink/Moxy : inheritance and attribute name oveloading based on type 了解自定义策略或 https://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm 如果您可以更改正在发布的 JSON。

这里有些讨论 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

【讨论】:

  • 如果您想将您的 JOINED 继承(鉴别器)字段命名为 type 而不是 typgc_typethrowing_type 等,那么这里的解决方案是什么?我认为这是/一直是一个非常糟糕的软件决定。
  • 我不明白您的问题,哪个软件决策不好? - EclipseLink 在需要时使用“TYPE”作为继承的默认字段名称(单表和连接表继承在 EclipseLink 中需要它)。如果您希望它使用其他内容,请指定 DiscriminatorColumn 注释。这里的问题是他们无意中将“TYPE”字段重用于其他内容,导致值发生冲突。
  • 其实这个事情发生的时候我在我的项目中改变了一些东西,但是现在我不能再重现它了。有一段时间,type 字段会导致一些异常,我认为这是一些内部命名决定。恐怕,我无法回到发生这种情况的时候,我上面的咆哮可能不再适用了。 (我不能在这里更改我的评论)
猜你喜欢
  • 2014-11-04
  • 1970-01-01
  • 2020-09-21
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多