This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

SDG: How to remove linkage between Domain Object and NodeBacked?Page Title Module

SDG: How to remove linkage between Domain Object and NodeBacked?

Sep 26th, 2011, 09:00 AM

Hey friends,

when loading a node out of NEO4Js graph database into our java domain object, there is a linkage between this object and the underlying NodeBacked object.
This linkage causes some limitations (for examle it is not possible to serialize the java object that is linked to the NodeBacked).

So back to the question: How can I remove this linkage between Domain Object and NodeBacked during runtime? Do i have to change the source code of Spring Data Graph 1.1.0?

Right now this is not possible and intended as the Node is used to access the data of your entity (it is not copied but read-through).
So for serializiation the way to go is to create a domain-level usecase-specific class that takes the data your other side needs and you copy it from your NodeEntity.

We are currently working on a second mapping strategy that uses the mapping abstractions of spring-data-commons and will not have a required backing-node after detachment (just a @GraphId).

Comment

Do you have an idea by when serializtion is possible for NodeEntities?
Copying the data to another domain class level will cause to much effort. We currently have to decide if we will use SDG in our project.

Comment

Do you have to serialize just the entity or its outgoing/incoming relationships too?

If you can change the SDG source code, you might try the following

(if I find time, I can also look into it).

have a NodeBacked.detach() method in the Aspect that copies the data from the node (just properties, not relationships) and then calls setPersistentState(null)
(if there is a graphid field it should also set the node/rel-id there).

Comment

I will try to get it in. Could you have a look at XStream which can also serialize to JSON?

The problem with whole subgraph serialization is that you have to define bounds. I would not like to have JPA/Hibernate like fetch-annotations.
But we would rather propose a way where you create domain objects that represent your Product with Subproducts (only containing properties and relationships that you want to serialize) and then use:

Comment

It just has to be a self contained subgraph, i.e. no outgoing Relationships to other parts of the Graphdb. So by copying all properties and following all outgoing relationships you effectively create a copy of the restricted subgraph which then could be serialized.

If the UseCaseSpecificProduct is not really specific to a use-case (i.e. limited number of properties and relationships of the original Product needed) then you could use inheritance to add additional properties and relationships for the normal Product.