AlsoLoad 該字段因此提供的名字都能被加載,良好的數據遷移
Collation
ConstructorArgs
Converters
Embedded 這個類會被做爲一個文檔裏的子文檔
Entity 實體類,
EntityListeners 指定外部生命週期事件實現類
Id 用來看成MongoDB中的_id字段
Index
Indexes 列出了Morphia應該建立的索引
Preperty 改變文檔中字段的名字
Reference 引用了其它的映射實體
Serialized 字段被轉換成二進制,而且被存儲
Text
Transient 被該註解註釋,該屬性不持久化
Validation 容許一個文檔驗證模式適用於全部寫入MongoDB的定義
Version 爲Entity提供一個樂觀鎖,動態加載,不須要設置值java
@Entity @Validation("{adt:{$gt:18}}") @Indexes({ @Index(fields = @Field(value = "adt", type = IndexType.DESC)), @Index(fields = @Field("CHD")) }) public class AnnotationTestEntity { @Id private ObjectId id;// 和entity成對出現 @Property("NewName") private String name;// 在數據庫中保存的是 "NewName" : "Tim" @Reference private AnnotationTest annotationTest; @Serialized private File streamFilter;// 該對象存儲的是序列化後的二進制 @Transient private String Transient;// 數據庫中沒有保存該屬性 @Indexed private int adt; @Collation(locale = "dddddd") private int CHD; @Version("version") private Long Version;// 必須爲long類型 @Embedded private School school; } @Entity public class AnnotationTest { @Id private String id; private int i; } @Embedded public class School { private String name; private String Address; }
存入數據庫後的結構git
{ "_id" : ObjectId("58db4f3fc0044b2d7bd5bf14"), "className" : "tops.front.operator.intl.inquirys.AnnotationTestEntity", "NewName" : "Tim", "annotationTest" : { "$ref" : "AnnotationTest", "$id" : "id" }, "streamFilter" : { "$binary" : "H4sIAAAAAAAAABWMsRHCMAwADYQOKNgDawBKDqp0TKDzmUTBsYyskLAPJWPRMgOY5ou/v399zDKLWXV4R0tsTxR8tXseN+v3d2FmtakSaqtmW/8LCBgbOKtQbPZTUuOg5d7DWPQVqSMPyinbi3BUy8kLKoulqKHgNpA8MmRx0CNFEJ95EOeLSv8jYEqBHCpxPJSBn9ROfRjnBqYfcI2stqgAAAA=", "$type" : "00" }, "adt" : 10, "CHD" : 145, "version" : NumberLong(1001), "school" : { "name" : "diyizhongxue", "Address" : "deizhi" } }
(若有不懂的請訪問http://mongodb.github.io/morphia/1.3/guides/annotations/)github