Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 与单个类有一对多关系的_Android_Ormlite - Fatal编程技术网

Android 与单个类有一对多关系的

Android 与单个类有一对多关系的,android,ormlite,Android,Ormlite,我猜我有一个名为Many的类。还有另外两个类One1和One2,它们有许多的集合: 第一类1: public class One1 { // ... @ForeignCollectionField(eager = false) private ForeignCollection<Many> events; } 公共一级1{ // ... @ForeignCollectionField(eager=false) 私人募捐活动; } 第二类: public c

我猜我有一个名为
Many
的类。还有另外两个类
One1
One2
,它们有许多
的集合:

第一类1:

public class One1 {
    // ...
    @ForeignCollectionField(eager = false)
    private ForeignCollection<Many> events;
}
公共一级1{
// ...
@ForeignCollectionField(eager=false)
私人募捐活动;
}
第二类:

public class One2 {
    // ...
    @ForeignCollectionField(eager = false)
    private ForeignCollection<Many> events;
}
公共一级2{
// ...
@ForeignCollectionField(eager=false)
私人募捐活动;
}
Many
实体一次只有一个关系。我的问题是:我应该如何在
Many
方面管理这种关系

编辑:


接下来是我的主意
Many
类有2个
外来
字段,并通过setter控制它们的填充
One1
One2
使用
foreignFieldName
属性引用
Many
中的不同字段。见下文:

许多

public class Many {

    @DatabaseField(foreign = true)
    private One1 mOne1;
    @DatabaseField(foreign = true)
    private One2 mOne2;

    public void setOne1(One1 one1) {
        mOne1 = one1;
        mOne2 = null;
    }

    public void setOne2(One2 one2) {
        mOne2 = one2;
        mOne1 = null;
    }
}
One1

public class One1 {
    @ForeignCollectionField(eager = false, foreignFieldName = "mOne1")
    private ForeignCollection<Many> mEvents;

    public ForeignCollection<Many> getEvents() {
        return mEvents;
    }
}
公共一级1{
@ForeignCollectionField(eager=false,foreignFieldName=“mOne1”)
私人外汇基金;
公共ForeignCollection getEvents(){
返回事件;
}
}
One2

public class One2 {

    @ForeignCollectionField(eager = false, foreignFieldName = "mOne2")
    private ForeignCollection<Many> mEvents;


    public ForeignCollection<Many> getEvents() {
        return mEvents;
    }


}
公共一级2{
@ForeignCollectionField(eager=false,foreignFieldName=“mOne2”)
私人外汇基金;
公共ForeignCollection getEvents(){
返回事件;
}
}

“许多实体一次只有一个关系”。这是否意味着
Many
可能与
One1
One2
有关系?而且永远不会同时做这两件事?是的。多侧中的P_ID持有一个1或一个2的ID