Database Reference
In-Depth Information
We have annotated our repository with @Repository so that the Spring frame-
work can consider it as a Spring managed repository and inject all the required
implementations of common CRUD operations, traversing and indexing.
2. Now, let's modify our Application-Config.xml file and add the following
piece of configuration anywhere between the <beans></beans> tags:
<neo4j:repositories
base-package="org.neo4j.spring.samples.repositories"/>
The preceding configuration provides the framework with the location and pack-
age of user-defined repositories. Spring framework will further scan the provided
package, that is, org.neo4j.spring.samples.repositories and
search for all interfaces that are marked with @Repository and will inject the
implementation required for performing CRUD and other search operations.
3. Next, let's enhance PersistNeo4JData and define the getAllMovies()
method and add @Autowired MovieRepository movieRepo; as an in-
stance variable. @Autowire will instruct the Spring framework to automatically
create the object of implementation provided for the MovieRepository inter-
face—or its parent interface, that is, GraphRepository —and assign its refer-
ence to the given variable.
4. Import java.util.Iterator as an additional package in Persis-
tNeo4JData .
5. Let's see the implementation of the getAllMovies() method that is very
simple and straightforward:
@Transactional
public void getAllMovies() {
Iterator<Movie> iterator =
movieRepo.findAll().iterator();
System.out.println("\n Start Dumping
Movies.............\n");
while (iterator.hasNext()) {
Movie movie = iterator.next();
System.out.println(" Movies ---> ID = " +
movie.getId() + ", Graph ID = "+ movie.getGraphId() +
", Title = " + movie.getTitle() + ", Year of Release
= " + movie.getYear());
Search WWH ::




Custom Search