0

ここで問題があります: 2 つのテーブル間に One2Many 接続を作成するにはどうすればよいですか?

メイン クラス: エリア

    @DatabaseTable(tableName = "AREA")
public class Area {

    public Area() { }

    @DatabaseField(generatedId = true)
    private int Id;

    public final static String AREA_ID = "AREA_ID";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.INTEGER, columnName = AREA_ID)
    public int AreaId;

    public final static String AREA_TITLE = "AREA_TITLE";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.STRING, columnName = AREA_TITLE)
    public String AreaTitle;

    public final static String AREA_LANG = "LANG";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.STRING, columnName = AREA_LANG)
    public String Language;

    @ForeignCollectionField(eager = false)
    public Collection<City> CityList;

    //data service load
    public Area(int id, String title, Collection<City> cities, String language) {
        AreaId = id;
        AreaTitle = title;
        SetCities(cities);
        Language = language;
    }

    private void SetCities(Collection<City> cities) {
        CityList = cities;
    }
}

子クラス:

@DatabaseTable(tableName = "CITY")
public class City {

    public City() { }

    @DatabaseField(generatedId = true)
    private int Id;

    public final static String CITY_ID = "CITY_ID";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.INTEGER, columnName = CITY_ID)
    public int CityId;

    public final static String CITY_TITLE = "CITY_TITLE";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.STRING, columnName = CITY_TITLE)
    public String CityTitle;

    public final static String CITY_LANG = "LANG";
    @DatabaseField(canBeNull = true, index = true, dataType = DataType.STRING, columnName = CITY_LANG)
    public String Language;

    public final static String AREA_ID = "AREA_ID";
    @DatabaseField(foreign = true, columnName = AREA_ID, canBeNull = false ,foreignAutoCreate = true,foreignAutoRefresh = true)
    private Area Area;


    public City(int id, String title, String language) {
        CityId = id;
        CityTitle = title;
        Language = language;
    }
}

の作成に例外はありませんが、AreaCityListです。どうすれば修正できますか?

前もって感謝します....

4

1 に答える 1

1

Area クラスの都市リストには、eager = true が必要だと思います

于 2012-11-01T08:41:25.117 に答える