DATADOC-56 added a section documenting _id conversion rules

This commit is contained in:
Thomas Risberg
2011-05-23 12:30:04 -04:00
parent 208c977e0a
commit c79989ce99

View File

@@ -142,7 +142,7 @@
<para>The repository is also <ulink
url="http://shrub.appspot.com/maven.springframework.org/milestone/org/springframework/data/">browseable
here</ulink>. </para>
here</ulink>.</para>
<para>You may also want to set the logging level to DEBUG to see some
additional information, edit the log4j.properties file and add</para>
@@ -707,6 +707,59 @@ Number of people = : 0</programlisting>
<para>The query stynax used in the example is explained in more detail in
the section <link linkend="mongo.query">Querying Documents</link>.</para>
<section>
<title>How the '_id' field is handled in the mapping layer</title>
<para>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 <classname>MongoMappingConverter</classname> there
are certain rules that govern how properties from the Java class is
mapped to this '_id' field. </para>
<para>The following outlines what property will be mapped to the '_id'
field:</para>
<para><itemizedlist>
<listitem>
<para>A property or field annotated with
<classname>@Id</classname>
(<classname>org.springframework.data.annotation.Id</classname>)
will be mapped to the '_id' field.</para>
</listitem>
<listitem>
<para>A property or field named <classname>id</classname> will be
mapped to the '_id' field.</para>
</listitem>
<listitem>
<para>A property or field declared as a String in the Java class
will be converted to and stored as an ObjectId if possible
(conversions and rules would be handled by the Mongo Java driver).
If it cannot be converted to an ObjectId, then the value will be
stored as a string in the database.</para>
</listitem>
<listitem>
<para>A property or field declared as anything but a String in the
Java class will be stored as the type it is declared as, which
means it must be one of the basic types supported by the Mongo
Java driver.</para>
</listitem>
</itemizedlist></para>
<para>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.</para>
<para>When querying and updating the <classname>JdbcTemplate</classname>
will use the converter to handle conversions of the
<classname>Query</classname> and <classname>Update</classname> 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.</para>
</section>
<section>
<title>Methods for saving and inserting documents</title>