Basically you have to split this into different tables, for ORMLite to handle it properly and have a clean db design.
You would end up having 4 tables: Temp_Contacts
, Contacts
, Email
and Phone
:
public class Temp_Contacts {
@DatabaseField(generatedId = true,canBeNull = false)
private int id;
// declare Contacts as a foreign key
// automatically fetched when Temp_Contacts is loaded
@DatabaseField(foreign=true, foreignAutoRefresh=true)
private Contacts contacts;
@DatabaseField
private Date data_actualizare;
...
}
Contacts:
public class Contacts {
@DatabaseField(id = true,canBeNull = false)
private int ID;
@DatabaseField
private String name;
// Use foreign collections for Telefon and Email
// that are loaded with Contacts
@ForeignCollectionField(eager = true)
private ForeignCollection<Telefon> numbers;
@ForeignCollectionField(eager = true)
private ForeignCollection<Email> emails;
...
}
Telefon and Email
public class Telefon {
// Reference to the Contact object has to be there
@DatabaseField(canBeNull = false, foreign = true)
private Contacs contacts;
...
}
public class Email {
// Reference to the Contact object has to be there
@DatabaseField(canBeNull = false, foreign = true)
private Contacs contacts;
...
}
This corresponds to the following db structure:
Temp_Contacts:
| id | contacts_id | data_actualizare |
Contacts:
| id | name |
Telefon and Email
| contacts_id | otherfields |
For more information on ForeignObjects
and ForeignCollections
see the ORMLite documentation