简体   繁体   English

在Morphia中使用瞬态

[英]Using transient in Morphia

I'm building an application using Play-Morphia and I'm trying to use transient on one of my fields in a class: 我正在使用Play-Morphia构建应用程序,并且试图在类的某个字段上使用transient:

transient public List names; 临时公共列表名称;

The reason I do this is that I want to save the list of names in the MongoDB using Morphia, but not to serialize it when I retrieve my class. 我这样做的原因是我想使用Morphia将名称列表保存在MongoDB中,而不是在检索类时将其序列化。 On Morphia's website http://code.google.com/p/morphia/ you can see this example: 在Morphia的网站http://code.google.com/p/morphia/上,您可以看到以下示例:

@Transient int notStored; @Transient int notStored; //fields can be ignored (no load/save) transient boolean stored = true; //可以忽略字段(无负载/保存)瞬态布尔值存储= true; //not @Transient, will be ignored by Serialization/GWT for example. //不是@Transient,例如将被序列化/ GWT忽略。

This is specifically says that the "stored" field can be saved to the MongoDB but will be ignored by Serialization. 特别是说“存储的”字段可以保存到MongoDB,但是被序列化忽略。

I tried to use it in my application, but in my case, "names" list didn't stored to the database. 我尝试在应用程序中使用它,但就我而言,“名称”列表未存储到数据库中。 Can anyone has an explanation for this? 有人可以对此进行解释吗? Thanks. 谢谢。

PlayMorphia module automatically add @Transient annotation to transient. PlayMorphia模块会自动将@Transient批注添加到瞬态。 Please submit an issue report on https://github.com/greenlaw110/play-morphia/issues to request disable this feature. 请在https://github.com/greenlaw110/play-morphia/issues上提交问题报告,以请求禁用此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM