Database Reference
In-Depth Information
Handy Hint
If you'd like to see what query SDN generates for your method, change the logging level
in your application to DEBUG. SDN uses SLF4J, so any framework that supports SLF4J
is acceptable; the tests in the sample code make use of Log4j.
As before, return types of
Iterable
indicate to SDN that you're expecting multiple pos-
sible entities, whereas a single domain entity indicates you're expecting just one. If you do
ever specify that you only expect one entity and the underlying query results in more than
one, SDN will throw an exception of the following sort:
NoSuchElementException: More than one element in IteratorWrapper(non-empty
iterator)
Multiple and nested properties
SDN is capable of understanding related property definitions. If you'd like to find all users
who were referred by any other user of a particular name (say Susan), you could define a
method as follows:
Iterable<User> findByReferredByName(String name);
Here the first part of the method references the
referredBy
property on the user. Then,
asthispropertyisitselfofthe
User
type,youproceedtosearchbasedonthe
name
ofthat
user.
You could string a whole lot of properties together and separate them with an
And
or
Or
term.(Currently,only
And
issupportedatruntimeforCypher.)Let'spretendthatyouruser
alsohadan
age
attribute.Inthiscase,ifyouwantedtofindalluserswithaparticularname
and age, you could define a method such as this:
Iterable<User> findByNameAndAge(String name, int age);
And much, much more
This brief section is nowhere near long enough to introduce the wealth of querying options
available, including sorting, range queries, and making use of the generic query methods
available through the
Neo4jTemplate
class. We hope we have provided a taste of the