spring - equivalent of template.createRelationBetween in SDN4 -
my project use spring-data-neo4j 3.3.0 , i'm trying use new 4.0.0.release version. in code have following code :
neo4jtemplate.createrelationshipbetween(eltorrel, attribute, valueclass, graphrelationtype.has_att_value, true)
what equivalent of code (which use this method in api in new version of sdk please ?
more don't know how create relation of given type specific class. how can write such creation in cypher please ?
@luanne here little example of problem.
class element :
@nodeentity public class element { @graphid private long id; private int age; private string uuid; @relationship(type = "has_att_value") private set<hasattvalue> values = new hashset<hasattvalue>(); ...
class attribute :
@nodeentity public class attribute { @graphid private long id; private string attname;
and class hasattvalue :
@relationshipentity(type = "has_att_value") public class hasattvalue { @graphid private long id; @startnode element element; @endnode attribute attribute; private string value; public hasattvalue() { } public hasattvalue(element element, attribute attribute, string value) { this.element = element; this.attribute = attribute; this.value = value; this.element.getvalues().add(this); }
in first case, works charm, and, in example have following graph (seeing in server browser) value on has_att_value relationshipentity:
(element)->[has_att_value]->(attribute)
but problem in following case (which working previous sdn). instead of hasattvalue previous class, have :
@relationshipentity(type = "has_att_value") public abstract class hasattvalue<t> { @graphid private long id; @startnode element element; @endnode attribute attribute; private t value; public hasattvalue() { } public hasattvalue(element element, attribute attribute, t value) { this.element = element; this.attribute = attribute; this.value = value; this.element.getvalues().add(this); }
with example 2 subclasses. first 1 :
public class hasbooleanvalue extends hasattvalue<boolean> { public hasbooleanvalue() { } public hasbooleanvalue(element elt, attribute attribut, boolean value) { super(elt, attribut, value); } }
second 1 :
public class hasstringvalue extends hasattvalue<string> { private string locale; public hasstringvalue() { } public hasstringvalue(element element, attribute attribut, string value) { super(element, attribut, value); }
in case graph following :
(element)->[has_att_value]->(hasbooleanvalue|hasstringvalue)->[attribute]->(attribute)
and arc in graphe (element)<-[element]-(hasbooleanvalue|hasstringvalue)
so how can have (element)->[has_att_value]->(attribute) "has_att_value" relationshipentity containing datas having diffent impletations in java code ? again, working in sdn3 when used neo4jtemplate.createrelationshipbetween(eltorrel, attribute, valueclass, graphrelationtype.has_att_value, true) create "hasattvalue" relationshipentity.
thank much
in sdn 4.0, relationships not need created explicitly using neo4jtemplate methods. persisting entity on @relationships defined enough create relationships. if have properties on relationship, you'd need @relationshipentity.
an explanation of object models in sdn 4.0 can found here http://graphaware.com/neo4j/2015/09/03/sdn-4-object-model.html
update based on additional info @clement:
just move @relationshipentity
annotation hasattvalue
class each subclass, example
@relationshipentity(type = "has_att_value") public class hasbooleanvalue extends hasattvalue<boolean> {
note need latest ogm snapshot since issue around abstract relationship entities fixed. please use
<dependency> <groupid>org.neo4j</groupid> <artifactid>neo4j-ogm</artifactid> <version>1.1.3-snapshot</version> </dependency> <repository> <id>neo4j-snapshots</id> <url>http://m2.neo4j.org/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> </repository>
or use sdn 4.1 snapshot
<dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-neo4j</artifactid> <version>4.1.0.build-snapshot</version> </dependency>
then graph should like
using cypher directly not idea you'd have able nodes (maybe id), mean have saved first.
Comments
Post a Comment