So I have created a general class called Food.
One of the FoodStuff I have are sweets so I have created a databaseTable called 'sweets' where 3 properties of the class are stored within class, namely, foodname, id and sugar levels of the sweets.
@DatabaseTable(tableName = "sweets")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Food implements Serializable {
@DatabaseField(id = true)
@JsonProperty
private String id; //for both sweets and meats
@DatabaseField
@JsonProperty
private String foodname; //for both sweets and meats
@DatabaseField
@JsonProperty
public int sugar; //for sweets only
@DatabaseField
@JsonProperty
public int protein; //for meats only
Now lets say I want to expand my android app by adding an extra tab at the top next to the 'sweets' tab which would display all foodstuff containing meats.
I want to add in an additional databaseTable into my sqlite database called meats and it should store only the foodname, id and protein levels.
Is this even possible using one class in ORMLite? I thought maybe it would look something like this but this doesn't work as it confuses ORMLite as to which table it should import the data into:
@DatabaseTable(tableName = "sweets")
@DatabaseTable(tableName = "meats")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Food implements Serializable {
@DatabaseField(id = true)
@JsonProperty
private String id;
@JsonProperty
private String foodname;
@JsonProperty
public int sugar;
@JsonProperty
public int protein;
Aucun commentaire:
Enregistrer un commentaire