update docs
look for entity collection on finds in mongotemplate
This commit is contained in:
@@ -105,11 +105,7 @@
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency></programlisting>
|
||||
</programlisting>
|
||||
|
||||
<para>The cglib dependency is there as we will use Spring's Java
|
||||
configuration style. Also change the version of Spring in the pom.xml to
|
||||
@@ -117,6 +113,11 @@
|
||||
|
||||
<programlisting lang="xml"><spring.framework.version>3.0.5.RELEASE</spring.framework.version></programlisting>
|
||||
|
||||
<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>
|
||||
|
||||
<programlisting>log4j.category.org.springframework.data.document.mongodb=DEBUG</programlisting>
|
||||
|
||||
<para>Next, in the org.spring.mongodb package in the sr/ctest/java
|
||||
directory create a class as shown below.</para>
|
||||
|
||||
@@ -145,7 +146,7 @@ public class MongoConfig extends AbstractMongoConfiguration {
|
||||
|
||||
<para>Then create a simple Person class to persist</para>
|
||||
|
||||
<programlisting>package org.spring.mongodb;
|
||||
<programlisting language="java">package org.spring.mongodb;
|
||||
|
||||
public class Person {
|
||||
|
||||
@@ -175,7 +176,42 @@ public class Person {
|
||||
|
||||
<para>And a main application to run</para>
|
||||
|
||||
<programlisting></programlisting>
|
||||
<programlisting language="java">package org.spring.mongodb;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.data.document.mongodb.MongoOperations;
|
||||
import org.springframework.data.document.mongodb.query.Criteria;
|
||||
import org.springframework.data.document.mongodb.query.Query;
|
||||
|
||||
public class MongoApp {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MongoApp.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class);
|
||||
MongoOperations mongoOps = ctx.getBean(MongoOperations.class);
|
||||
|
||||
mongoOps.insert(new Person("1234", "Joe"));
|
||||
|
||||
log.info(mongoOps.findOne(new Query(Criteria.where("name").is("Joe")), Person.class));
|
||||
}
|
||||
|
||||
}</programlisting>
|
||||
|
||||
<para>This will produce the following output</para>
|
||||
|
||||
<programlisting>MongoPersistentEntityIndexCreator] - <Analyzing class class org.spring.mongodb.Person for index information.>
|
||||
LoggingEventListener] - <onBeforeConvert: Person [id=1234, name=Joe]>
|
||||
LoggingEventListener] - <onBeforeSave: Person [id=1234, name=Joe], { "_id" : "1234" , "name" : "Joe"}>
|
||||
MongoTemplate] - <insert DBObject: { "_id" : "1234" , "name" : "Joe"}>
|
||||
LoggingEventListener] - <onAfterSave: Person [id=1234, name=Joe], { "_id" : "1234" , "name" : "Joe"}>
|
||||
MongoTemplate] - <findOne using query: { "name" : "Joe"} in db.collection: database.person>
|
||||
LoggingEventListener] - <onAfterLoad: { "_id" : "1234" , "name" : "Joe"}>
|
||||
LoggingEventListener] - <onAfterConvert: { "_id" : "1234" , "name" : "Joe"}, Person [id=1234, name=Joe]>
|
||||
MongoApp] - <Person [id=1234, name=Joe]></programlisting>
|
||||
</section>
|
||||
|
||||
<section id="mongodb-connectors">
|
||||
|
||||
Reference in New Issue
Block a user