XO 与属性的关系抛出异常

XO Relation with properties throws exception

一个jQAssistant plugin, I created a relationship descriptor as described in http://buschmais.github.io/extended-objects/doc/0.8.0/neo4j/#_unidirectional_relations

看起来像这样:

@Relation
public interface PlantUmlSequenceDiagramMessageDescriptor 
    extends Descriptor {

    @Relation.Outgoing
    PlantUmlParticipantDescriptor getSourceParticipant();

    @Relation.Incoming
    PlantUmlParticipantDescriptor getTargetParticipant();

    void setMessage(String messageText);
    String getMessage();

    void setMessageNumber(String messageNumber);
    String getMessageNumber();
}

但使用时:

final PlantUmlSequenceDiagramMessageDescriptor messageDescriptor = 
    store.create(p1, PlantUmlSequenceDiagramMessageDescriptor.class, p2);

我遇到异常:

2017-12-21 19:37:16.591 [main] ERROR ScannerImpl - Unexpected problem encountered while scanning: item='plantuml\src\test\plantuml\sequence.puml', path='/sequence.puml', scope='NONE', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.FileResourceSc
annerPlugin@65d93024, de.kontext_e.jqassistant.plugin.plantuml.scanner.PlantUmlFileScannerPlugin@72dcb917]'. Please report this error including the full stacktrace (continueOnError=true).
com.buschmais.xo.api.XOException: Cannot resolve property in type 'de.kontext_e.jqassistant.plugin.plantuml.store.descriptor.PlantUmlParticipantDescriptor' for relation type 'de.kontext_e.jqassistant.plugin.plantuml.store.descriptor.PlantUmlSequenceDiagramMessag
eDescriptor'.
    at com.buschmais.xo.impl.metadata.RelationTypeMetadataResolver.getRelationPropertyMethodMetadata(RelationTypeMetadataResolver.java:131)
    at com.buschmais.xo.impl.metadata.MetadataProviderImpl.getPropertyMetadata(MetadataProviderImpl.java:146)
    at com.buschmais.xo.impl.XOManagerImpl.createByExample(XOManagerImpl.java:288)
    at com.buschmais.xo.impl.XOManagerImpl.create(XOManagerImpl.java:272)
    at com.buschmais.jqassistant.core.store.impl.AbstractGraphStore.create(AbstractGraphStore.java:83)
    at de.kontext_e.jqassistant.plugin.plantuml.scanner.PumlLineParser.addEvent(PumlLineParser.java:286)

创建具有属性的关系的正确方法是什么?我已经尝试过为传出和传入关系添加设置器,但没有帮助。

您创建关系的方式是正确的。但是,异常消息表明您尚未映射 PlantUmlParticipantDescriptor 中的关系。在您的情况下,PlantUmlParticipantDescriptor 界面应如下所示:

@Label
public interface PlantUmlParticipantDescriptor {
    @Relation.Outgoing
    Set<PlantUmlSequenceDiagramMessageDescriptor> getSource();

    @Relation.Incoming
    Set<PlantUmlSequenceDiagramMessageDescriptor> getTarget();
}

@Relation
public interface PlantUmlSequenceDiagramMessageDescriptor {

    @Relation.Outgoing
    PlantUmlParticipantDescriptor getSourceParticipant();

    @Relation.Incoming
    PlantUmlParticipantDescriptor getTargetParticipant();

    void setMessage(String messageText);
    String getMessage();

    void setMessageNumber(String messageNumber);
    String getMessageNumber();
}

然后你可以按预期设置属性:

PlantUmlParticipantDescriptor  t1 = this.xoManager.create(PlantUmlParticipantDescriptor.class);
PlantUmlParticipantDescriptor  t2 = this.xoManager.create(PlantUmlParticipantDescriptor .class);
PlantUmlSequenceDiagramMessageDescriptor d = this.xoManager.create(t1, PlantUmlSequenceDiagramMessageDescriptor.class, t2);
d.setMessage("Test Message");