Eclipse MOXy Unmarshall异常:数据库行中缺少类指示符字段

时间:2019-01-15 20:43:04

标签: java jaxb eclipselink moxy

我在解组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 :(得分:0)

当前,MOXy要求继承指示符位于XML属性中。如果它在XML元素中,则可以对XmlAdapter使用以下方法。