I have a problem with greenDao and @ToMany relation. Drning session when i'm doing insertion to DB i can get @ToMany relation easily. My problem occurs after I'm restarting my application, list that is being returned is empty.
Daily.class
@Entity
public class Daily extends BaseObservable implements Parcelable {
@Id(autoincrement = true)
private Long id;
@Unique
private String tag;
@SerializedName("summary")
@Expose
private String summary;
@SerializedName("icon")
@Expose
private String icon;
@SerializedName("data")
@Expose
@ToMany(joinProperties = {
@JoinProperty(name = "tag", referencedName = "dataTag")})
@OrderBy("id ASC")
private List<DailyData> data = new ArrayList<DailyData>();
DailyData.class
@Entity
public class DailyData extends BaseObservable implements Parcelable {
@Id(autoincrement = true)
private Long id;
@NotNull private String dataTag;
... [rest of the code]
Place where I'm doing insert to DB (I'm using rxjava2 to get model). I've been trying inserting it in different order but there is no affect also.
public void insertCityToDatabase(City city) {
city.setName(cityLatLngList.get(getPosition()).getResult().getName());
city.getDailyWithoutId().setTag(city.getName());
city.getHourlyWithoutId().setTag(city.getName());
for (HourlyData hourlyData : city.getHourlyWithoutId().getHourlyDataWithoutId()) {
hourlyData.setDataTag(city.getName());
daoSession.insert(hourlyData);
}
for (DailyData dailyData : city.getDailyWithoutId().getDataWithoutId()) {
dailyData.setDataTag(city.getName());
daoSession.insert(dailyData);
}
daoSession.insert(city.getHourlyWithoutId());
daoSession.insert(city.getDailyWithoutId());
daoSession.insert(city.getCurrentlyWithoutId());
long id = daoSession.insert(city);
eventBus.post(new NewCity(id));
}
Here is my DB Daily and DailyData, debuger Android Studio
I have also tried doing @ToMany relation by @ToMany(referencedJoinProperty = "id") but the result is the same.
Any idea why @ToMany relation is not working?