I have a Java model similar to:
public class Country {
@Id private String id;
private CurrencyId currencyId;
private List<Province> provinceList;
...
}
public class Province {
@Id private String id;
private Gobernor gobernorId;
private List<City> cityList;
...
}
public class City {
@Id private String id;
private String name;
...
}
I want to store that data using objectify. However, as Country data might change, I also want to store the date the Country data has been stored, so I think I should store an entity such as:
public class CountryListEntity {
@Id private String id;
private List<Country> countryList;
private Date storeDate;
}
Note I will only have one entity of kind CountryListEntity with the Id “root”, if I can store it like that. I know very little about both how google apps stores data and how objectify works. I’ve tried many combinations of @Embedded, but I got many errors, i.e.
Cannot place array or collection properties inside @Embedded arrays or collections
Can anyone tell me how to define these classes? A snippet of the code needed to store and retrieve this “root” entity, would be highly appreciated!
@Embedded collections are transformed into a series of collection fields in the
low-level Entity. That’s why one level embedding is all you can do.
If you are going to store/load all data at once and if your entities are as simple as the ones in your example you can put @Serialized annotation for your lists inside @Embedded lists.
You can find out more from this discussion.
The problem with this approach is that your low-level embeddings won’t be able to be indexed.