Ankit Gupta
Ankit Gupta

Reputation: 2599

grails neo4j how to define relationship and their properties

In grails-neo4j plug-in,how can i define relationship among nodes and properties of relationship.

I can define my nodes as domain classes but what if i want to connect nodes i.e. i want to map relationship of nodes in some form.

I found spring-neo4j framework which works well for this case and i can map relationship to java class but didn't find any grails compatibility layer for this.

Upvotes: 0

Views: 151

Answers (3)

Chris Malan
Chris Malan

Reputation: 137

It is now much later than when this question was originally asked - 4 years later. The plugin now supports Neo4j relationships being created as Grails domain classes and the relationship can have attributes. However, constraints on these attributes do not work yet. Below is the full code for a working, one-way relationship.

package neo4j.authentication.demo

import grails.neo4j.Relationship
import groovy.transform.CompileStatic

@CompileStatic
class BelongsTo implements Relationship<Car, Owner> {

    String sinceWhen

    String toString() {
        sinceWhen
    }
}

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39905

Mapping domain classes as relationships is not yet supported in the Neo4j Grails plugin. I have this on my list of stuff to add.

You're right, Spring Data Neo4j already is capable of doing this. Be aware that Spring Data Neo4j and the Grails Neo4j plugin have nothing in common (aside that they use Neo4j to persist). The persistence layer is a completely separate code base.

Upvotes: 0

injecteer
injecteer

Reputation: 20699

the plugin doesn't map the domain classes directly to nodes or relations in neo4j. It uses its own structure, like:

root -> domainClass.name -> relation -> domain class instance

I'd recommend to define your domain classes as nodes, and the plugin should handle them properly. Another way: abandon the plugin >)

Upvotes: 1

Related Questions