下面的'.2F'值不会保留。我没有错误,但只返回null。您能否建议对以下代码进行更正或改进?我试图将其保留在GAE测试数据库中。
我在试图使用EmbeddedMap时留下了评论,但是,我认为没有必要,因为我使用的是简单类型的Map。
public class UserBeanApp extends Model {
private static final long serialVersionUID = 1L;
@Id(Generator.AUTO_INCREMENT)
public Long id;
@Unindexed
private RequiredReturnsBean requiredReturns;
public RequiredReturnsBean getReqRetBean() {
if (requiredReturns == null)
requiredReturns = new RequiredReturnsBean();
else
requiredReturns.get();
return requiredReturns;
}
}
public class RequiredReturnsBean extends Model {
@Id(Generator.AUTO_INCREMENT)
public Long id;
// @EmbeddedMap
// public static class RequiredReturn {
// public RequiredReturn(Float requiredReturn) {
// this.val = requiredReturn;
// }
//
// public Float val;
// }
@Unindexed
@Embedded
public Map<Long, Float> requiredReturn = new HashMap<Long, Float>();
public Map<Long, Float> getReqRetMap() {
if (requiredReturn == null) {
requiredReturn = new HashMap<Long, Float>();
}
return requiredReturn;
}
}
...创建......
UserBeanApp bean = get....//already persisted
RequiredReturnsBean rrBean = bean.getReqRetBean();
rrBean.getReqRetMap().put(1L, .2F);
rrBean.save();
...选择......
UserBeanApp bean = get....//already persisted
RequiredReturnsBean rrBean = bean.getReqRetBean();
requiredReturn = rrBean.getReqRetMap().get(1L);//always null
GAE-1.6.0 锡耶纳-2.0.6