MongoDB’s ORM framework Morphia uses Morphia (mapping object)
Mapping Objects Once we’ve annotated our objects, there’s a lot of heavy lifting to do. Now all we have to do is create a Morphia instance, tell Morphia what classes we want to map, and then we can Started mapping between Mongo documents and Java objects. Create a Morphia instance (create a Morphia instance) The first thing you have to do is create a Morphia instance and tell him the class you want to map. It is recommended that you only create a Morphia instance once and reuse it. import com.google.code.morphia.Morphia; … Morphia morphia = new Morphia(); morphia. map(BlogEntry. class) .map(Author.class); … Any class you map will be validated, and if for some reason your mapped class is invalid a MappingException will be thrown. You can also tell Morphia to scan a package, mapping all the classes in the package. … morphia.mapPackage(“my.package.with.only.mongo.entities”); … Advanced Usage (advanced application) Manually use Morphia to map to DBObjects to interact directly through the java driver. Here are some examples of how to use it. Mapping a java for Persistence Manually use Morphia to map to DBObjects…