We wanted to add repositories with domain-specific operations. We started by creating a movie-specific repository, simply by creating an empty interface. It is more convenient to work with a named interface rather than different versions of a generic one.
Example 8.1. Movie repository
package org.neo4j.cineasts.repository; public interface MovieRepository extends GraphRepository<Movie> {}
Then we added it to the Spring context configuration by simply adding:
Example 8.2. Repository context configuration
<neo4j:repositories base-package="org.neo4j.cineasts.repository"/>
We then created the domain-specific repository class, annotating it with @Repository
and
@Transactional
, and injected the movie repository.
Example 8.3. Domain-specific repository
@Repository @Transactional public class CineastsRepostory { @Autowired MovieRepository movieRepository; public Movie getMovie(int id) { return movieRepository.findByPropertyValue("id", id); } }
We did the same for the actors and users.