convert @NodeEntity to Node

183 views
Skip to first unread message

Daniel Aschauer

unread,
May 9, 2012, 5:22:36 AM5/9/12
to ne...@googlegroups.com
How can I can convert a node object annotated with @NodeEntity to a org.neo4j.graphdb.Node?
In other words:
I use SDN and use the repository to get an object from the graph, but I would like to perform some operations based on a org.neo4j.graphdb.Node.

Michael Hunger

unread,
May 9, 2012, 5:24:46 AM5/9/12
to ne...@googlegroups.com
Node node = template.getPersistentState(object)

Michael

Daniel Aschauer

unread,
May 9, 2012, 5:33:01 AM5/9/12
to ne...@googlegroups.com
Thanks.
Is there another way, when I am dealing with a Object that haven't
been persisted yet.
I want to create a new Node and copy properties from another.

2012/5/9 Michael Hunger <michael...@neotechnology.com>:

Michael Hunger

unread,
May 9, 2012, 5:43:04 AM5/9/12
to ne...@googlegroups.com
you mean neo4jTemplate.setPersistentState(object, node)

and then template.save(object) ?

Michael

Daniel Aschauer

unread,
May 11, 2012, 6:38:15 AM5/11/12
to ne...@googlegroups.com
The main problem I have is to deal with (Neo4J) Node and (Spring Data Neo4j) NodeEntitys.
When I take a Node and copy all properties and save it it is not in the index and not retrievable with spring data repository.
How can I convert a node to its according @NodeEntity and save it this way?

Daniel Aschauer

unread,
May 11, 2012, 7:29:53 AM5/11/12
to ne...@googlegroups.com
I experienced and found that I can manually can convert by reading the __type__ and then resave the @NodeEntity:

template.save(template.convert(node, Class.forName((String) node.getProperty("__type__"))));

Michael Hunger

unread,
May 11, 2012, 2:28:48 PM5/11/12
to ne...@googlegroups.com
Daniel,

sorry I'm not really understanding your use-case what do you want to achieve?

Michael

Daniel Aschauer

unread,
May 14, 2012, 4:15:54 AM5/14/12
to ne...@googlegroups.com
They usecase is the same as described in another post "copy nodes to
compose subgraph" and the topic got a bit mixed up.
I read a subgrah, copy the nodes and want to save them but using the
mapped @NodeEntity, so that indexes and repository finder methods work
right.
As you posted I guess the template.postEntityCreation(node,clazz) is
what I need.
Thanks,
Daniel

2012/5/11 Michael Hunger <michael...@neotechnology.com>:
>>> > 2012/5/9 Michael Hunger <michael...@neotechnology.com>:
Reply all
Reply to author
Forward
0 new messages