我知道极度混乱的头衔。
您好,我在这里面临一些时髦的问题。
我有一个属性类,就像这样
@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;
}
和
@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-class,但那会觉得很糟糕。 我想到的另一个解决方案是创建一个包含Propertys列表的超类,然后让Factory和Store继承这个类,应该让它们共享索引,我认为...... 我应该跳过所拥有的关系并选择无主的关系吗?
我觉得我可能会遗漏一些至关重要的东西。 有什么想法吗?
由于
答案 0 :(得分:0)
在拥有的关系中,属性只能属于一个类。 你还应该在父类中添加属性的链接,然后
离。
Proprety
@Persistent
private Store store;
存储
@Persistent(mappedBy = "store")
private List<Property> protperties;
如果要在商店和工厂类中使用相同的属性,则必须使用无主关系解决方案。
厂
@Persistent
private Set<Key> properties;
存储
@Persistent
private Set<Key> properties;