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) { ... }
}

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务