Database Reference
In-Depth Information
This means that you can take advantage of this same mechanism to handle any custom
classtypesthatyoumaywanttouse,suchasaphonenumberobject.You'llneedtowritea
custom converter and register it with Spring. The topic's sample code provides an example
of how to do this by adding a phoneNumber to the User entity. For more details on
this conversion mechanism, please refer to chapter 6 of the Spring Framework Reference
Documentation , http://static.springsource.org/spring/docs/current/spring-framework-refer-
ence/html/validation.html#core-convert .
If you don't register a converter, SDN will still save a string version of your object into the
database.However,itwillsimplybebasedonwhateverisreturnedfromthe toString()
method.
You've probably noticed that an additional field appears to have snuck into both the User
and Movie node entities, namely nodeId , annotated with @GraphId . This is a man-
datory SDN requirement when using simple object mapping. Without going into too much
detail just yet, simple object mapping is one of the strategies employed by SDN to per-
form the physical mapping between your domain entity and the Neo4j-backed graph en-
tity. Using this strategy, SDN needs to have a field where it can store the underlying ID of
the node backing the entity. The @GraphId annotation serves to mark the field that
you've set aside for SDN to store this value in. Read more about simple object mapping in
section 9.4.1 .
Indexed properties
As it's generally considered bad practice for an application to rely on the Neo4j node ID as
anexternaluniqueidentifierofanobject(seethe“ Notes on the lookup benchmark ”sidebar
in section 5.6.1 for details), it's important to have some other way of looking up a node.
The addition of the @Indexed annotation on the userId field in the previous bit
of code ensures that lookups and queries can be performed against this user based on this
field. By default, @Indexed uses schema-based indexes, which rely on Neo4j labels. The
code to look up the entity will be covered in section 9.3 , but internally Neo4j uses exactly
the same schema-indexing code and logic as described in section 5.5.1 to accomplish this.
Search WWH ::




Custom Search