Reputation: 12857
Item
@DatabaseTable
public class Item {
@DatabaseField(generatedId = true, canBeNull = false, columnName = "id")
public int id;
@DatabaseField(canBeNull = true, foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
public Enclosure enclosure;
}
Enclosure
@DatabaseTable
public class Enclosure {
@DatabaseField(generatedId= true, columnName = "id", canBeNull = false)
private long id;
@DatabaseField
private String url;
@ForeignCollectionField(eager = true)
protected ForeignCollection<Item> items;
}
R.raw.ormlite_config.txt
#################################
# --table-start--
dataClass=com.rssproject.Item
tableName=rssitems
# --table-fields-start--
# --field-start--
fieldName=id
generatedId=true
# --field-end--
# --field-start--
fieldName=enclosure
# --field-end--
# --table-fields-end--
# --table-end--
#################################
#################################
# --table-start--
dataClass=com.rssproject.Enclosure
tableName=rssenclosure
# --table-fields-start--
# --field-start--
fieldName=id
generatedId=true
# --field-end--
# --field-start--
fieldName=url
indexName=rssenclosure_string_idx
# --field-end--
# --table-fields-end--
# --table-end--
#################################
DatabaseHelper
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
}
insert:
List<Item> list = daoRuntimeItem.queryForAll();
daoRuntimeEnclosure.create(item.getEnclosure());
daoRuntimeItem.create(item);
Error is :
java.lang.IllegalArgumentException: ORMLite does not know how to store class com.rssproject.Enclosure for field enclosure. Use another class or a custom persister.
Upvotes: 2
Views: 2201
Reputation: 3353
As said in your comment, you wrote the ormlite_config.txt
manually, which is a bad idea. ORMLite provides an utility to write that file for you, which be a lot easier :)
Please take a look at this page to have more information : http://ormlite.com/docs/table-config
Upvotes: 2