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

时间:2014-11-18 17:11:45

标签: java spring rest spring-data-neo4j spring-data-rest

我对spring-data-neo4j-rest有一个非常简单的问题:因为我在@NodeEntity中放了一个@RelatedToVia关系,@ StatusNode和@EndNode在我的GETs中出现在@Entity上,如下面的JSON: / p>

{
   "_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;
    }

}

1 个答案:

答案 0 :(得分:0)

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

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