Urr4
Urr4

Reputation: 793

OGM Custom Query using Custom Label

I have a Neo4j/OGM Entity Person which I mapped to the Label User using @NodeEntity(label="User). I now want to write a custom Query MATCH (p:Person) where.... As far as I see, there is no way to use my Application-Side Type Person instead of the Graph-Side Label User like in Hibernate, right? If there is a way, please explain how to do this, or tell my a key-word to google for. Same question goes for entity properties.

Thank you.

Update: Lets say I have a User class like so:

@NodeEntity(label="Person")
class User {
@Property(name="username")
   private String name;
   ...
}

I've used the Mapping to obtain loose coupling so I can eg. rename the Person and won't affect the Neo4j. And in the Neo4j there are for example Houses with Relationships to Users. Now I want to load all Houses, referencing a User with the name "Sven", so the Statement would be MATCH (h:House)-[:HOLDS]->(p:Person {username:'Sven'}). Given, that I might have a huge poject with all the entities in some submodule somewhere else, I might not know, that User is mapped to Person and the user.name is mapped to username, so in a Hibernate environment, I would query as MATCH (h:House)-[:HOLDS]->(u:User {name:'Sven'}). However in OGM this doesn't seem to work. There might be a way to solve this architectually but in some projects you don't have this choise.

So the question in the End is: Is there some way to get this to work, or do I really need to know the mapping of every entity i use?

Upvotes: 0

Views: 168

Answers (1)

nmervaillie
nmervaillie

Reputation: 1270

You can do this in several ways :

  • Make your User extend a Person class
  • if you need more dynamic labels, the class can contain an @Labelsannotated list of labels to apply. See the documentation for more details

About properties, I don't see how this would be useful. Interested to hear about the use case.

Upvotes: 1

Related Questions