EclipseLink: Missing class for indicator field value of typ
Asked Answered
R

3

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?

Ranchod answered 13/10, 2015 at 13:39 Comment(4)
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 #8943445 for custom strategies or eclipse.org/eclipselink/documentation/2.4/moxy/… if you can change the JSON being postedDonation
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.Ranchod
Is there any explanation why EclipseLink fails and Hibernate not?Ranchod
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.Donation
D
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

Donation answered 14/10, 2015 at 13:1 Comment(3)
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.Fusibility
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.Donation
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)Fusibility
G
11

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

Gertrudgertruda answered 16/6, 2016 at 19:38 Comment(1)
This was actually my problem.. saved me there.Applicable
D
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

Donation answered 14/10, 2015 at 13:1 Comment(3)
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.Fusibility
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.Donation
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)Fusibility
N
0

Eclipselink found a record with the mentioned inheritance discriminator value "Miss". You need to specify a inherited class, which defines that type with @DiscriminatorValue(value = "Miss").

If you have many such undefined types, it is questionable if inheritance is a good decision. You may consider to change your model to an aggregation, where you aggregate the inherited entity in the inherited class and define a "type" field as a normal column in the inherited class.

If you do not need the inherited type "Miss" at all, you may catch the DescriptorException / PersistenceException.

Nureyev answered 20/10, 2023 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.