mongoDB http://www.mongodb.org/
Morphia https://github.com/mongodb/morphia
DZone http://architects.dzone.com/articles/using-morphia-map-java-objects
MongoDB with Querydsl http://blog.mysema.com/2010/11/mongodb-with-querydsl.html
Querydsl http://www.querydsl.com/
Morphia is a lightweight type-safe library for mapping Java objects to/from MongoDB. Morphia provides a typesafe, and fluent Query API support with (runtime) validation. Morphia uses annotations so there are no XML files to manage or update. Morphia should feel very comfortable for any developer with JPA experience.
- Lifecycle Method/Event Support
- Works great with Guice, Spring, and other DI frameworks.
- Many extension points (new annotations, converters, mapping behavior, logging, etc.)
- Does not store Null/Empty values (by default).
- GWT support (entities are just POJOs) -- (GWT ignores annotations)
- Advanced mapper which allows raw conversion,
void toObject(DBObject)
orDBObject fromObject(Object)
Please continue by reading the QuickStart or looking at a list of the annotations. If you have further questions, please reach out to us on our mailing list.
Quick start
Including morphia in your build
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>0.107</version>
</dependency>
See the dependencies page for more detail.
import com.mongodb.DBObject;
import org.bson.types.ObjectId;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.annotations.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Entity("employees")
public class Employee {
@Id
private ObjectId id;
// value types are automatically persisted
private String firstName;
private String lastName;
// only non-null values are stored
private Long salary = null;
// by default fields are @Embedded
private Address address;
//references can be saved without automatic loading
private Key<Employee> manager;
//refs are stored**, and loaded automatically
@Reference
private List<Employee> underlings = new ArrayList<Employee>();
// stored in one binary field
// @Serialized EncryptedReviews;
//fields can be renamed
@Property("started")
private Date startDate;
@Property("left")
private Date endDate;
//fields can be indexed for better performance
@Indexed
private boolean active = false;
//fields can loaded, but not saved
@NotSaved
private String readButNotStored;
//fields can be ignored (no load/save)
@Transient
private int notStored;
//not @Transient, will be ignored by Serialization/GWT for example.
private transient boolean stored = true;
//Lifecycle methods -- Pre/PostLoad, Pre/PostPersist...
@PostLoad
void postLoad(DBObject dbObj) {
}
public Employee() {
}
public Employee(String firstName, String lastName, Key<Employee> manager, long salary) {
this.firstName = firstName;
this.lastName = lastName;
this.manager = manager;
this.salary = salary;
}
// getter and setter
......
}
public class Address {
private String country;
private String city;
private String address;
private String postcode;
// getter and setter
......
}
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.Morphia;
import org.mongodb.morphia.query.UpdateResults;
import java.net.UnknownHostException;
public class EmployeeRepository {
private Morphia morphia;
private Datastore ds;
public static void main(String[] args) {
EmployeeRepository repository = new EmployeeRepository();
repository.init();
repository.test();
}
public void init() {
try {
Mongo mongo = new MongoClient(new ServerAddress("localhost", 27017));
morphia = new Morphia();
ds = morphia.createDatastore(mongo, "testdb");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public void test() {
ds.save(new Employee("Mister", "GOD", null, 0L));
// get an employee without a manager
Employee boss = ds.find(Employee.class).field("manager").equal(null).get();
Key<Employee> scottsKey = ds.save(new Employee("Scott", "Hernandez", ds.getKey(boss), 150 * 1000));
//add Scott as an employee of his manager
UpdateResults<Employee> res = ds.update(boss, ds.createUpdateOperations(Employee.class).add("underlings", scottsKey));
// get Scott's boss; the same as the one above.
Employee scottsBoss = ds.find(Employee.class).filter("underlings", scottsKey).get();
for (Employee e : ds.find(Employee.class, "manager", boss))
System.out.println(e.getLastName() + " " + e.getFirstName());
}
}
Note: @Reference will not save objects, just a reference to them; You must save them yourself.
相关推荐
后续提交放在https://github.com/zdsiyan/watermelon 上, 用eclipse导入该工程需安装m2eclipse,jetty等查件. 另外.settings下的org.eclipse.wst.common.component文件如下: ...</project-modules>
spring-mongodb-morphia springdata-mongo morphia mongodb 学习
Morphia MongoDB示例 是的对象/文档映射器。 CI
Information for F# developer who want to using MongoDB.
morphia基于mongodb的基本开发
中断更改:play-morphia 1.5.0将morphia库更新为org.mongodb.morphia 0.107。 请在您的应用程序中将文本从“ com.google.code.morphia”替换为“ org.mongodb.morphia” PlayMorphia概述 PlayMorphia模块一个功能...
使用Morphia框架操作mongodb
MongoDB是面向文档的开源数据库,Morphia是面向MongoDB 的类型安全的对象映射库。本文解释了在文档和对象之间进行映射的好处,并演示了如何使用Morphia来实现这个功能。然后演示了如何持久保存、加载、删除和查询...
spring4.2 集成mongodb框架morphia1.1 代码实现和配置
cdn, 在fly图像裁剪/调整,通过 MongoDb with的内容传递网络 #CDN 上的GridFs 这个实用工具可以作为独立的内容传递网络,使用MongoDB作为后端文件存储。 它可以从源代码生成,也可以作为已经编译的二进制文件安装。...
涉及到的技术栈分别为:Spring Boot,MongoDB,Morphia. 数据模型 @Data @Builder @Entity(value = "rawDevStatus", noClassnameStored = true) // 设备状态索引 @Indexes({ // 设置数据超时时间(TTL,MongoDB根据...
NULL 博文链接:https://gaozzsoft.iteye.com/blog/1460827
Play 应用程序中的身份验证和授权 该项目是具有身份验证和授权功能的多模块播放应用程序的示例实现。 这附有一篇。 Play 被选为开发此应用程序的主要框架,因为它具有惊人的生态系统、插件和其他好处,例如 Akka、...
mongoMorphiaDemo mongoDB 上 morphia 演示的简单演示——这是“Java for MongoDB”课程的演示代码: : 该演示将展示如何使用开源项目将 java 对象插入/更新到 MongoDB: Morphia(Morphia 项目: : ) 项目模型:...
mongodb入门小书,简单快速高效!可以看看,快速了解mongodb的基本用法!
Morphia操作MongoDB,进行增删查改操作,内附详细代码。
and transferring data between Oracle and MongoDB * How to use Kundera, Spring Data, and Spring XD with MongoDB * How to load MongoDB data into Oracle Database and integrating MongoDB with Oracle ...
使用.NET Core測試驅動 MongoDB 那麼,蘋果和橙子有什麼區別? 除了蘋果和橙子都是水果並且可以榨汁外,它們沒有太多共同之處。 蘋果含有更多的纖維,而橙子含有更多的維生素C。比較蘋果和橙子的成語是指蘋果和...
Web Development with MongoDB and Node(3rd) 英文epub 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
JavaScript Applications with Node.js, React, React Native and MongoDB: Design, code, test, deploy and manage in Amazon AWS By 作者: Eric Bush ISBN-10 书号: 0997196661 ISBN-13 书号: 9780997196665 出版...