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!The following outlines what type conversion, if any, will be done on the property mapped to the _iddocument field.• If a field named 'id' is declared as a String or BigInteger in the Java class it will be converted to andstored as an ObjectId if possible. ObjectId as a field type is also valid. If you specify a value for 'id' inyour application, the conversion to an ObjectId is delected to the <strong>MongoDB</strong>driver. If the specified 'id'value cannot be converted to an ObjectId, then the value will be stored as is in the document's _id field.• If a field named ' id' id field is not declared as a String, BigInteger, or ObjectID in the Java class thenyou should assign it a value in your application so it can be stored 'as-is' in the document's _id field.• If no field named 'id' is present in the Java class then an implicit '_id' file will be generated by the driverbut not mapped to a property or field of the Java class.When querying and updating MongoTemplate will use the converter to handle conversions of theQuery and Update objects that correspond to the above rules for saving documents so field namesand types used in your queries will be able to match what is in your domain classes.7.2 Mapping ConfigurationUnless explicitly configured, an instance of MongoMappingConverter is created by default whencreating a MongoTemplate. You can create your own instance of the MappingMongoConverter soas to tell it where to scan the classpath at startup your domain classes in order to extract metadata andconstruct indexes. Also, by creating your own instance you can register <strong>Spring</strong> converters to use formapping specific classes to and from the database.You can configure the MongoMappingConverter as well as com.mongodb.Mongo andMongoTemplate either using Java or XML based metadata. Here is an example using <strong>Spring</strong>'s Javabased configuration1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 78

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

Saved successfully!

Ooh no, something went wrong!