开发者

Holding different instances of the same class in GAE Datastore

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(开发者_Go百科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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜