繁体   English   中英

通过REST获取实体时,Spring Data Neo4j Rest显示StartNode和EndNode

[英]Spring Data Neo4j Rest displays StartNode and EndNode when GETting entities via REST

我对spring-data-neo4j-rest有一个非常简单的问题:由于我在我的@NodeEntity中放置了@RelatedToVia关系,因此@StartNode和@EndNode出现在我的@Entity的GET中,就像下面的JSON一样:

{
   "_embedded":{
      "fields":[
         {
            "label":"Field 1",
            "_links":{
               "self":{
                  "href":"http://localhost/fields/5"
               },
               "startField":{
                  "href":"http://localhost/fields/5/startField"
               },
               "endField":{
                  "href":"http://localhost/fields/5/endField"
               },
               "fieldValues":{
                  "href":"http://localhost/fields/5/fieldValues"
               },
               "form":{
                  "href":"http://localhost/fields/5/form"
               }
            }
         }
      ]
   }
}

我的问题是:为什么会发生这种情况,因为startnode和endnode不是nodeentity的一部分,我如何防止这种行为发生?

抱歉,如果我的问题格式不正确,这里是第一个问题,如果需要,我将进行编辑。

谢谢 !

====其他信息====

这是我的申请

 @Configuration
    @EnableNeo4jRepositories
    @Import(RepositoryRestMvcConfiguration.class)
    @EnableAutoConfiguration
    public class Application extends Neo4jConfiguration {

        public Application() {
            setBasePackage("com.oliverstore.badger.server");
        }

        @Bean(destroyMethod = "shutdown")
        public GraphDatabaseService graphDatabaseService() {
            return new GraphDatabaseFactory().newEmbeddedDatabase("/opt/ostore/badger/data/badger-server.db");
        }

        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }

简而言之,我将仅在此处粘贴出现问题的一个NodeEntity和RelationshipEntity。

节点:

@NodeEntity
public class Field {

    @GraphId private Long id;

    @Indexed(unique = true)
    private String label;

    @RelatedTo(type="HAS_FIELD", direction=Direction.BOTH)
    private @Fetch Form form;

    @RelatedTo(type="HAS_VALUE", direction=Direction.BOTH)
    private @Fetch Set<FieldValue> fieldValues = new HashSet<FieldValue>();

    @RelatedToVia(type="EVENTS_WITH")
    @Fetch private Set<Event> events = new HashSet<Event>();

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public Form getForm() {
        return form;
    }

    public void setForm(Form form) {
        this.form = form;
    }

    public Set<FieldValue> getFieldValues() {
        return fieldValues;
    }

    public void setFieldValues(Set<FieldValue> fieldValues) {
        this.fieldValues = fieldValues;
    }


    public void add(Field targetField, String propertyLabel, String valueLabel){
        Event event = new Event(this, targetField, propertyLabel, valueLabel);
        this.events.add(event);
    }
}

关系:

@RelationshipEntity(type="EVENTS_WITH")
public class Event {

    @GraphId private Long id;

    @StartNode
    private Field startField;
    @EndNode
    private Field endField;

    String propertyLabel;
    String valueLabel;

    public Event(){
    }

    public Event(Field startField, Field endField, String propertyLabel,
            String valueLabel) {
        this.startField = startField;
        this.endField = endField;
        this.propertyLabel = propertyLabel;
        this.valueLabel = valueLabel;
    }

    public String getPropertyLabel() {
        return propertyLabel;
    }
    public String getValueLabel() {
        return valueLabel;
    }

}

您可以使用@JsonIgnore批注忽略Json中的关系实体。

@RelatedToVia(type="EVENTS_WITH")
@Fetch 
@JsonIgnore
private Set<Event> events = new HashSet<Event>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM