From 7ea14bb4d571e30a32243067b1370a176aaa6964 Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Fri, 27 May 2011 13:13:23 -0400 Subject: [PATCH] Add failing test PersonPojoWithPrimitiveIdTests DATADOC-147 - Update reference documentation to cover changes from M2 to M3 (partial work) --- src/docbkx/reference/mapping.xml | 123 +++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 5 deletions(-) diff --git a/src/docbkx/reference/mapping.xml b/src/docbkx/reference/mapping.xml index 147186361..057f8856a 100644 --- a/src/docbkx/reference/mapping.xml +++ b/src/docbkx/reference/mapping.xml @@ -7,13 +7,126 @@ Rich maping support is provided by the MongoMappingConverter. MongoMappingConverter has a rich metadata model that - provides a full feature set of functionality to map domain objects into - MongoDB documents. The mapping metadata model is populated using annotations - on your domain objects but is not limited to using annotations as the only - source of metadata information. In this section we will describe the - features of the MongoMappingConverter and how to specify annotation based + provides a full feature set of functionality to map domain objects to + MongoDB documents.The mapping metadata model is populated using annotations + on your domain objects. However, the infrastructure is not limited to using + annotations as the only source of metadata information. The + MongoMappingConverter also allows you to map objects + to documents without providing any additional metadata, by following a set + of conventions. + + In this section we will describe the features of the + MongoMappingConverter. How to use conventions for mapping objects to + documents and how to override those conventions with annotation based mapping metadata. + + SimpleMongoConverter has been deprecated in + Spring Data MongoDB M3 as all of its functionality has been subsumed into + MappingMongoConverter. + + +
+ Convetion based Mapping + + MongoMappingConverter has a few conventions for mapping objects to + documents when no additional mapping metadata is provided. The conventions + are: + + + + The short Java class name is mapped to the collection name in + the following manner. The class + 'com.bigbank.SavingsAccount' maps to + 'savingsAccount' collection name. + + + + All nested objects are stored as nested objects in the document + and *not* as DBRefs + + + + The converter will use any Spring Converters registered with it + to override the default mapping of object properties to document + field/values. + + + + Public JavaBean properties + + + + You can have a single non-zero argument constructor whose + constructor argument names match top level field names of document, + that constructor will be used. Otherewise the zero arg constructor + will be used. if there is more than one non-zero argument constructor + an exception will be thrown. + + + +
+ How the '_id' field is handled in the mapping layer + + Mongo requires that you have an '_id' field for all documents. If + you don't provide one the driver will assign a ObjectId with a generated + value. When using the MongoMappingConverter there + are certain rules that govern how properties from the Java class is + mapped to this '_id' field. + + The following outlines what property will be mapped to the '_id' + document field: + + + + A property or field annotated with + @Id + (org.springframework.data.annotation.Id) + will be mapped to the '_id' field. + + + + A property or field without an annotation but named + id will be mapped to the '_id' + field. + + + + The following outlines what type conversion, if any, will be done + on the property mapped to the _id document field when using the + MappingMongoConverter, the default for + MongoTemplate. + + + + An id property or field declared as a String in the Java class + will be converted to and stored as an ObjectId if possible using a + Spring Converter<String, ObjectId>. Valid conversion rules are + delegated to the Mongo Java driver. If it cannot be converted to an + ObjectId, then the value will be stored as a string in the + database. + + + + An id property or field declared as BigInteger in the Java + class will be converted to and stored as an ObjectId using a Spring + Converter<BigInteger, ObjectId>. + + + + If no field or property specified above is present in the Java + class then an implicit '_id' file will be generated by the driver but + not mapped to a property or field of the Java class. + + When querying and updating MongoTemplate + will use the converter to handle conversions of the + Query and Update objects + that correspond to the above rules for saving documents so field names + and types used in your queries will be able to match what is in your + domain classes. +
+
+
MongoDB Mapping Configuration