i have an issue here: How can i create an One2Many connection between two tables?
Main Class: Area
@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;
}
}
Child class:
@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;
}
}
I don't have any exception on create of Area
, but CityList
is empty, how can i fix that?
Thanks in advance....