0

非常混乱的标题,我知道。

您好,我在这里面临一些时髦的问题。

我有一个属性类,像这样

@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 类,但这会让人感觉很糟糕。我正在考虑的另一个解决方案是创建一个包含属性列表的超类,然后让 Factory 和 Store 从这个类继承,应该让它们共享索引,我认为......我应该跳过拥有的关系并继续无主?

我觉得我可能只是错过了一些重要的东西。有任何想法吗?

谢谢

4

1 回答 1

0

在拥有的关系中,财产只能属于一个类别。您还应该在父类中添加指向该属性的链接

前任。

财产

@Persistent
private Store store;

店铺

@Persistent(mappedBy = "store")
private List<Property> protperties;

如果你想在 store 和 factory 类中使​​用相同的属性,你必须使用 unowned 关系解决方案。

工厂

@Persistent
private Set<Key> properties;

店铺

@Persistent
private Set<Key> properties;
于 2011-04-04T22:51:37.770 回答