8

My application runs on Payara and provides a REST API but when I try to create an object with a POST request I get the following exception:

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

On the contrary everything is fine and no errors occur when I am executing the program on Wildfly which uses Hibernate.

Entities:

@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();
}

I think that Eclipselink has problems to unmarshal my json. Do I need any additional annotation?

ammerzon
  • 998
  • 1
  • 13
  • 30
  • 1
    Joined inheritance will by default use a 'type' field to determine the entity class to use, as does json/xml marshalling. You have a type field, but populated it with "Miss' which can't be converted to a class. see http://stackoverflow.com/questions/8942945/eclipselink-moxy-inheritance-and-attribute-name-oveloading-based-on-type for custom strategies or https://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm if you can change the JSON being posted – Chris Oct 13 '15 at 17:33
  • I renamed the attribute to throwingType which solved my problem. Could you please post your comment as answer so I can mark it as answer. – ammerzon Oct 14 '15 at 07:26
  • 2
    Is there any explanation why EclipseLink fails and Hibernate not? – ammerzon Oct 14 '15 at 07:30
  • Hibernate does not bother with a type field when using joined inheritance in the database, as it can use query joining mechanisms. EclipseLink does use the type under the belief it is more efficient to filter out unneeded joins, and also has to contend with JSON/XML where joins aren't possible. – Chris Oct 14 '15 at 12:59

2 Answers2

11

You will get this error if you use a field named "type".

Alex Wade
  • 659
  • 1
  • 7
  • 27
6

Joined inheritance will by default use a 'type' field to determine the entity class to use, as does json/xml marshalling. You have a type field, but populated it with "Miss' which can't be converted to a class.

See eclipselink/Moxy : inheritance and attribute name oveloading based on type for custom strategies or https://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm if you can change the JSON being posted.

The type field within JPA is somewhat discussed here http://www.coderanch.com/t/489497/ORM/databases/InheritanceType-JOINED-DiscriminatorColumn and here https://en.wikibooks.org/wiki/Java_Persistence/Inheritance#No_class_discriminator_column_2

Community
  • 1
  • 1
Chris
  • 20,138
  • 2
  • 29
  • 43
  • So what is the solution here if you WANT to name your JOINED inheritance (discriminator) field `type` and not `typ`, `gc_type`, `throwing_type` etc.? I think this is / has been a really bad software decision. – Kawu Jan 14 '20 at 03:06
  • I don't understand your issue, what software decision was bad? - EclipseLink uses "TYPE" as the default field name for inheritance when required (single and joined table inheritance requires it in EclipseLink). If you want it to use something else, specify the DiscriminatorColumn annotation. Question here was they were inadvertently reusing the "TYPE" field for something else, causing the values to conflict. – Chris Jan 14 '20 at 16:24
  • Actually I changed some things in my project when this thing occurred, but now I cannot reproduce it anymore. There was a time when a `type` field caused some exceptions, which I thought was some internal naming decision. I'm afraid, I cannot get back to the point when this happened and my rant above probably isn't applicable anymore. (and I cannot change my comment here) – Kawu Jan 15 '20 at 14:29