JDO 和 AppEngine 的子属性
我有以下代码:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true") 公共A类{ @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @PrimaryKey 私钥密钥;
@Persistent
private B b;
@Persistent
private int id;
// ...
@PersistenceCapable
(identityType = IdentityType.APPLICATION, detachable="true") 公共B类{ @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @PrimaryKey 私钥密钥;
@Persistent
private int id;
// ...
现在
我需要做的是检索 B 的实例,并从 A 的实例引用它,如下所示:
B b = DAL.getBById(1); A a = 新A(); a.setB(b);
当我将 a 传递给 PersistenceManager 的 makePersistent() 方法时,发生了两件我不需要的事情:
1)创建了 B 的新实例 2)A对b的引用为空
有人能告诉我我做错了什么吗?
谢谢!
I have the following code:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class A {
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@PrimaryKey
private Key key;
@Persistent
private B b;
@Persistent
private int id;
// ...
}
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
public class B {
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@PrimaryKey
private Key key;
@Persistent
private int id;
// ...
}
Now what I need to be able to do, is retrieve an instance of B, and refer to it from an instance of A like this:
B b = DAL.getBById(1);
A a = new A();
a.setB(b);
When I pass a to the makePersistent() method of the PersistenceManager, two things that I don't need happen:
1) a new instance of B is created
2) the reference A makes to b is null
Could someone tell me what I am doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字段值可以包含可序列化类的实例,将该实例的序列化值存储在 Blob 类型的单个属性值中。为了告诉 JDO 序列化该值,该字段使用注释 @Persistent(serialized=true)。 Blob 值未编入索引,并且不能在查询过滤器或排序顺序中使用。
下面是一个简单的 Serialized 类的示例,它表示一个文件,包括文件内容、文件名和 MIME 类型。这不是 JDO 数据类,因此没有持久性注释。
}要将 Serialized 类的实例存储为属性中的 Blob 值,请声明一个类型为该类的字段,并使用 @Persistent(serialized = "true") 注释:
在您的情况下,您可以使用
然后在中声明它你的数据类
A field value can contain an instance of a Serializable class, storing the serialized value of the instance in a single property value of the type Blob. To tell JDO to serialize the value, the field uses the annotation @Persistent(serialized=true). Blob values are not indexed and cannot be used in query filters or sort orders.
Here is an example of a simple Serializable class that represents a file, including the file contents, a filename and a MIME type. This is not a JDO data class, so there are no persistence annotations.
}To store an instance of a Serializable class as a Blob value in a property, declare a field whose type is the class, and use the @Persistent(serialized = "true") annotation:
I your case you can use
Then declare it in your data class