13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

please define productname in your docbook file!6. <strong>MongoDB</strong> repositories6.1 IntroductionThis chapter will point out the specialties for repository support for <strong>MongoDB</strong>. This builds on the corerepository support explained in Chapter 4, Working with <strong>Spring</strong> <strong>Data</strong> Repositories. So make sure you'vegot a sound understanding of the basic concepts explained there.6.2 UsageTo access domain entities stored in a <strong>MongoDB</strong> you can leverage our sophisticated repository supportthat eases implementing those quite significantly. To do so, simply create an interface for your repository:public class Person {@Idprivate String id;private String firstname;private String lastname;private Address address;}// … getters and setters omittedExample 6.1 Sample Person entityWe have a quite simple domain object here. Note that it has a property named id of typeObjectId.The default serialization mechanism used in MongoTemplate (which is backing the repositorysupport) regards properties named id as document id. Currently we supportString, ObjectId andBigInteger as id-types.public interface PersonRepository extends PagingAndSortingRepository {}// additional custom finder methods go hereExample 6.2 Basic repository interface to persist Person entitiesRight now this interface simply serves typing purposes but we will add additional methods to it later. Inyour <strong>Spring</strong> configuration simply add1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 70

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!