ORMLite 不知道如何存储 class
ORMLite does not know how to store class
项目
@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;
}
外壳
@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--
#################################
数据库助手
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
}
插入:
List<Item> list = daoRuntimeItem.queryForAll();
daoRuntimeEnclosure.create(item.getEnclosure());
daoRuntimeItem.create(item);
错误是:
java.lang.IllegalArgumentException: ORMLite does not know how to store class com.rssproject.Enclosure for field enclosure. Use another class or a custom persister.
正如您在评论中所说,您手动编写了 ormlite_config.txt
,这是个坏主意。 ORMLite 提供了一个实用程序来为您编写该文件,这要容易得多:)
请查看此页面以获取更多信息:http://ormlite.com/docs/table-config
项目
@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;
}
外壳
@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--
#################################
数据库助手
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION, R.raw.ormlite_config);
}
插入:
List<Item> list = daoRuntimeItem.queryForAll();
daoRuntimeEnclosure.create(item.getEnclosure());
daoRuntimeItem.create(item);
错误是:
java.lang.IllegalArgumentException: ORMLite does not know how to store class com.rssproject.Enclosure for field enclosure. Use another class or a custom persister.
正如您在评论中所说,您手动编写了 ormlite_config.txt
,这是个坏主意。 ORMLite 提供了一个实用程序来为您编写该文件,这要容易得多:)
请查看此页面以获取更多信息:http://ormlite.com/docs/table-config