在 GAE 数据存储中保存同一类的不同实例

发布于 2024-10-30 02:20:39 字数 1614 浏览 0 评论 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;
}

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请恋爱 2024-11-06 02:20:40

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

添加。

属性

@Persistent
private Store store;

存储

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

如果您想在存储和工厂类中使用相同的属性,则必须使用无主关系解决方案。

工厂

@Persistent
private Set<Key> properties;

@Persistent
private Set<Key> properties;

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

@Persistent
private Store store;

Store

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

If you want to use the same properties in the store and factory class you have to go with the unowned relationship solution.

Factory

@Persistent
private Set<Key> properties;

Store

@Persistent
private Set<Key> properties;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文