4

I got a graph which is described by the following Cypher expression:

CREATE
(BMW:Brand {name: "BMW", country: "Germany"}),
(X3:Model {name: "X3", acceleration: 7.1, maxSpeed: 227.5, displacement: 1997, consumption: 6}),
(lastGen:Generation {from: 2013}),
(xDrive20i:Modification {name: "xDrive20i", maxSpeed: 210, acceleration: 8.3, consumption: 7.9}),
(X3)-[:MODEL_OF]->(BMW),
(BMW)-[:MODEL]->(X3),
(lastGen)-[:GENERATION_OF]->(X3),
(X3)-[:GENERATION]->(lastGen),
(xDrive20i)-[:MODIFICATION_OF]->(X3),
(X3)-[:MODIFICATION]->(xDrive20i),
(lastGen)-[:MODIFICATION]->(xDrive20i),
(xDrive20i)-[:MODIFICATION_OF]->(lastGen);

I described a java class matching to Brand's data structure:

@NodeEntity
@TypeAlias("Brand")
public class Brand {

    @GraphId
    private Long id;

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "brand_name")
    private String name;

    private String origin;

    private String owner;

    @RelatedTo(type = "MODEL", direction = Direction.OUTGOING)
    private Set<Model> models;

    //getters and setters are ommited
}

and repository:

public interface BrandRepository extends GraphRepository<Brand>{

    //method's signatures are ommited

}

When I call brandRepository.count() it returns 1 as I expect. But if I call brandRepository.getOne(2249L) I get an exception:

java.lang.IllegalStateException: No primary SDN label exists .. (i.e one with starting with __TYPE__)

As I understand reading LabelBasedNodeTypeRepresentationStrategy source, a node has to have at least one label with __TYPE__ prefix.

How do I map the entity to the graph given that I may not change the graph structure?

I wouldn't mind implementing my own custom LabelBasedNodeTypeRepresentationStrategy if there is no other way. But in this case could somebody let me know why it is implemented this way (I think it is not accidentally) and how should I bind custom solution to spring-data-neo4j use it?

I use neo4j-2.0.0-M06 and spring-data-neo4j-3.0.0.M1.

Oleg Kurbatov
  • 1,376
  • 1
  • 19
  • 32
  • I didn't find an answer to my question but I approached to my problem another way. I changed to Ruby technologies and used [neo4j](https://github.com/andreasronge/neo4j) gem. It acts exactly as I expect at least not adding meta-information to my data. – Oleg Kurbatov Mar 12 '14 at 06:44

1 Answers1

2

SDN adds additional metadata to your graph when you store entities, that metadata is missing in your case.

You can try to add that metadata yourself by calling

neo4jTemplate.postEntityCreation(node, Brand.class);

but that for instance doesn't index your name field (manual legacy index).

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Thank you for reply. This approach gives me a chance of getting entities from data which has been imported using Cypher expression but price of it is metadata changes the data. I have no objections against metadata, I'm against poluting user-space with metadata. – Oleg Kurbatov Jan 17 '14 at 08:00
  • Can I avoid presence the metadata in the data by any means? And how that may cause troubles in the future? – Oleg Kurbatov Jan 17 '14 at 08:06
  • 1
    @RandomFreeman yes, don't use SDN, use [neo4j](http://docs.neo4j.org/chunked/stable/tutorials-java-embedded.html). The metadata isn't pollution if you need SDN, because SDN needs the metadata, therefore you need the metadata. it's pollution if you *don't* need (and/or want) anything SDN gives you, and in that case, if this "pollution problem" is that important to you, you should look into using the java API directly. – drew moore Jul 11 '14 at 10:03
  • 1
    @Micheal Hunger how about when you want to delete a node with the repo.deleteAll()? I am getting the same error and it seems to come up abruptly even though all my nodes are created with SDN. – F.O.O Jan 29 '15 at 18:05