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

mefy6pfw  于 11个月前  发布在  其他
关注(0)|答案(3)|浏览(114)

我的应用程序运行在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();
}


我认为JavaScript链接在解组我的json时有问题。我需要任何额外的注解吗?

x7rlezfr

x7rlezfr1#

如果使用名为“type”的字段,则会出现此错误。

vjhs03f7

vjhs03f72#

联合继承默认使用“type”字段来确定要使用的实体类,就像json/xml编组一样。您有一个type字段,但使用“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中有一些讨论

2izufjch

2izufjch3#

Increaselink发现了一个带有上述继承值“Miss”的记录。您需要指定一个继承类,该继承类使用@DiscriminatorValue(value =“Miss”)定义该类型。
如果你有很多这样的未定义类型,那么继承是否是一个好的决定是值得怀疑的。你可以考虑将你的模型改为一个聚合,在那里你将继承的实体聚合在继承的类中,并在继承的类中定义一个“type”字段作为普通列。
如果你根本不需要继承类型“Miss”,你可能会捕获DescriptorException / PersistenceException。

相关问题