0
votes

I have a very simple issue with spring-data-neo4j-rest : since I put a @RelatedToVia relation in my @NodeEntity, @StartNode and @EndNode appeared in my GETs on that @Entity like in the following 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"
               }
            }
         }
      ]
   }
}

My question is : why does this happen as startnode and endnode are not part of the nodeentity and how can I prevent this behaviour from happening ?

Sorry in advance if my question is not well formed, first question here, I will edit if asked to.

Thank you !

==== ADDITIONAL INFO ====

Here is my application

 @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);
        }
    }

To be shorter I will only paste here the one NodeEntity and RelationshipEntity who are issues.

Node :

@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);
    }
}

Relationship :

@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
And what exactly is your question?František Hartman
Edited my question, thanks !Kevin Herdier

1 Answers

0
votes

You can ignore Relationship Entities being there in the Json using @JsonIgnore annotation.

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