Hi.
I am new to Spring, in particular Spring Data Neo4j, and despite some problems getting everything running I am very excited about what I see.
I have a question on code structure, that stems from me having absolutely no idea what is going on under the hood (and also from lack of experience). From all the examples I have seen, the domain have consisted of simple classes without any hierachy (apart from java.lang.Object, of course).
From what I have learned about software architecture, you should implement some interface in order to decouple your implementation. Also, I feel an urge to factor out whatever I can, and therefore thought I would make a class such as
This way I implement these two important methods once and for all, and at the same time encapsulate the node id.Code:abstract class GraphEntity { @GraphId private Long nodeId; @Override public boolean equals(Object o) { return o == this || o != null && getClass() == o.getClass() && nodeId.equals(((GraphEntity) o).nodeId); } @Override public int hashCode() { return nodeId != null ? nodeId.hashCode() : super.hashCode(); } }
All domain classes backed by a node or relationship would then inherit from this, and at the same time implement the respective domain interface, e.g.
I would put the interfaces in one package ([app].domain), and GraphEntity and the implementations in another one ([app].domain.impl)Code:@NodeEntity public class MovieNode extends GraphEntity implements Movie { ... }
What do you think? Pros/cons/better ways? Problems with the mapping system? Any thoughts are appreciated.
Regards, Michael.


Reply With Quote
