Morphia 介绍
Morphia 是一个轻量级的类型安全的 Java 类库,用来将在
MongoDB 和 Java 对象之间进行映射。
@Entity("employees") class Employee { @Id ObjectId id; // auto-generated, if not set (see ObjectId) String firstName, lastName; // value types are automatically persisted Long salary = null; // only non-null values are stored @Embedded Address address; @Reference Employee manager; // refs are stored*, and loaded automatically @Reference List<Employee> underlings; // interfaces are supported @Serialized EncryptedReviews; // stored in one binary field @Property("started") Date startDate; //fields can be renamed @Property("left")Date endDate; @Indexed boolean active = false; //fields can be indexed for better performance @NotSaved string readButNotStored; //fields can read, but not saved @Transient int notStored; //fields can be ignored (load/save) transient boolean stored = true; //not @Transient, will be ignored by Serialization/GWT for example. //Lifecycle methods -- Pre/PostLoad, Pre/PostSave... @PostLoad void postLoad(DBObject dbObj) { ... } }
Morphia 官网
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。