在 GAE 数据存储中保存同一类的不同实例
我知道,标题极其令人困惑。
您好,我在这里面临一些奇怪的问题。
我有一个属性类,就像这样
@PersistenceCapable
public class Property implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
//...
}
现在,我还有另外两个类。我们称它们为“工厂”和“商店”。 它们都有这样的属性:
@PersistenceCapable
public class Factory implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String m_Name;
@Persistent
private List<Property> m_FactoryProperties;
}
and
@PersistenceCapable
public class Store implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String m_Name;
@Persistent
private List<Property> m_StoreProperties;
}
虽然这看起来很简单,但行不通。 我不知道为什么,我猜测它与索引相关,因为在 GAE 的数据查看器中,当我查看属性实体时,有一个 m_FactoryProperties_INTEGER_IDX 或 m_StoreProperties_INTEGER_IDX 。 (它们永远不会同时出现)。
(如果我将列表重命名为 m_Propertys 也不起作用)...
这不可能吗? 我可以创建一个 FactoryProperty 和 StoreProperty 类,但这会让人感觉非常错误。 我正在考虑的另一个解决方案是创建一个包含属性列表的超类,然后让 Factory 和 Store 从此类继承,这应该使它们共享索引,我认为...... 我应该跳过拥有的关系并选择无主的关系吗?
我觉得我可能错过了一些重要的东西。 有什么想法吗?
谢谢
Extremly confusing title, i know.
Hello, i am facing some funky issues here.
I have a property-class, like this
@PersistenceCapable
public class Property implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
//...
}
Now, i also have two other classes. Lets call them Factory and Store.
They both have propertys, like this:
@PersistenceCapable
public class Factory implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String m_Name;
@Persistent
private List<Property> m_FactoryProperties;
}
and
@PersistenceCapable
public class Store implements Serializable
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String m_Name;
@Persistent
private List<Property> m_StoreProperties;
}
While this does look simple, it will not work.
And i have no idea why, im guessing its index-related, as in the Data Viewer of GAE there is either a m_FactoryProperties_INTEGER_IDX or a m_StoreProperties_INTEGER_IDX when i view property entities. (They never appear at the same time).
(Does not work if i rename to lists to m_Propertys either)...
Is this not possible?
I COULD make a FactoryProperty- and StoreProperty-class, but that would feel horrible wrong.
Another solution im thinking about is making a superclass that holds a list of Propertys, and then have Factory and Store inherit from this class, that SHOULD make them share the index, i think...
Should i just skip the owned relationships and go for unowned?
I feel that i may just missing something crucial.
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在拥有关系中,财产只能属于一个类别。
您还应该添加一个指向父类中的属性的链接,然后
添加。
属性
存储
如果您想在存储和工厂类中使用相同的属性,则必须使用无主关系解决方案。
工厂
店
In an owned relationship property can only belong to one class.
you also should add a link to the property in the parent class then
ex.
Proprety
Store
If you want to use the same properties in the store and factory class you have to go with the unowned relationship solution.
Factory
Store