Eclipse MOXy Unmarshall Exception: Отсутствует поле индикатора класса из строки базы данных - PullRequest
0 голосов
/ 15 января 2019

У меня проблема при удалении сообщения XML. Тем не менее, маршалинг работает отлично. Я использую наследование через аннотацию экстрактора класса XML.

Не могли бы вы помочь мне определить проблему здесь?

Исключение:

Caused by: Exception [EclipseLink-44] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class indicator field from database row [org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl@631330c].
Descriptor: XMLDescriptor(main.TransitionGuard --> [])
    at org.eclipse.persistence.exceptions.DescriptorException.missingClassIndicatorField(DescriptorException.java:961)
    at org.eclipse.persistence.internal.oxm.XMLRelationshipMappingNodeValue.processChild(XMLRelationshipMappingNodeValue.java:85)
    at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.startElement(XMLCompositeObjectMappingNodeValue.java:385)
    at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.startElement(UnmarshalRecordImpl.java:864)
    at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parseEvent(XMLStreamReaderReader.java:138)
    at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:102)
    at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:89)
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:940)
    at org.eclipse.persistence.internal.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:655)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:637)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:216)
    ... 1 more

Вот мои занятия:

Переход

public class Transition {

    private String from;

    private String to;

    TransitionGuard guard;

    public Transition() {
        // For Moxy
    }

    public Transition(String from, String to) {
        this(from, to, null);
    }

    public Transition(String from, String to, TransitionGuard guard) {
        setFrom(from);
        setTo(to);
        setTransitionGuard(guard);
    }

    @XmlAttribute(name = "from")
    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    @XmlAttribute(name = "to")
    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    @XmlElement(name = "guard")
    public TransitionGuard getTransitionGuard() {
        return guard;
    }

    public void setTransitionGuard(TransitionGuard guard) {
        this.guard = guard;
    }

}

TransitionGuard

@XmlClassExtractor(TransitionGuardClassExtractor.class)
@XmlSeeAlso({ ExceptionGuard.class, ScriptedGuard.class })
public abstract class TransitionGuard {

}

TransitionGuardClassExtractor

public class TransitionGuardClassExtractor extends ClassExtractor {
    @Override
    public Class extractClassFromRow(Record record, Session session) {
        if (null != record.get("/abpm:exception-guard")) {
            return ExceptionGuard.class;
        } else if (null != record.get("/abpm:scripted-guard")) {
            return ScriptedGuard.class;
        }
        return null;
    }
}

ScriptedGuard

public class ScriptedGuard extends TransitionGuard {

    String script;

    public ScriptedGuard() {
    }

    public ScriptedGuard(String script) {
        setScript(script);
    }

    @XmlPath("abpm:scripted-guard/text()")
    @XmlCDATA
    public String getScript() {
        return script;
    }

    public void setScript(String script) {
        this.script = script;
    }

}

TestPE

@XmlRootElement(name = "TestPE")
public class TestPE {

    List<Transition> transition;

    public List<Transition> getTransition() {
        return transition;
    }

    public void setTransition(List<Transition> transition) {
        this.transition = transition;
    }


}

пакет-информация

@XmlSchema(namespace = "jelly:com.werken.blissed.jelly.BlissedTagLibrary", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
    @XmlNs(prefix = "version", namespaceURI = "4.7"), @XmlNs(prefix = "j", namespaceURI = "jelly:core"),
    @XmlNs(prefix = "abpm", namespaceURI = "jelly:com.adeptia.indigo.jelly.IndigoTagLibrary"),
    @XmlNs(prefix = "pd", namespaceURI = "jelly:com.adeptia.indigo.pd.ProcessDesignerTagLibrary"),
    @XmlNs(prefix = "", namespaceURI = "jelly:com.werken.blissed.jelly.BlissedTagLibrary") })
package main;

import javax.xml.bind.annotation.XmlNs;

Входной XML

<?xml version="1.0" encoding="UTF-8"?>
<TestPE xmlns:version = "4.7" xmlns:j = "jelly:core" xmlns:abpm = "jelly:com.adeptia.indigo.jelly.IndigoTagLibrary" xmlns:pd = "jelly:com.adeptia.indigo.pd.ProcessDesignerTagLibrary" xmlns = "jelly:com.werken.blissed.jelly.BlissedTagLibrary" >
    <transition from="state-BPMN:GATEWAY:XOR_DATA_GATEWAY-892276265" to="state-BPMN:EVENT:END_EVENT-892276264" >
        <guard>
            <abpm:scripted-guard><![CDATA[*** Script ***]]></abpm:scripted-guard>
        </guard>
    </transition>
</TestPE>

Демонстрационный код

Map<String, String> properties = new HashMap<String, String>();
properties.put("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
JAXBContext jc = JAXBContext.newInstance(new Class[] { TestPE.class }, properties);
// JAXB unmarshall
Unmarshaller unmarshaller = jc.createUnmarshaller();
TestPE testPE = (TestPE) unmarshaller.unmarshal(new File("resources/Transition.xml"));

1 Ответ

0 голосов
/ 17 января 2019

В настоящее время MOXy требует, чтобы индикатор наследования был в атрибуте XML. Если он находится в элементе XML, вы можете использовать следующий подход с XmlAdapter .

...