我希望通过 ormlite 4.48 保留两个遗留类。 这些课程无法修改,因此我无法使用优秀的注释。
幸运的是,DatabaseTableConfig
来救援。
这是我的课程:
public class RedditLink extends RedditType {
// Thing
private String id;
private String name;
private String kind;
private String data;
// Votable
private int ups;
private int downs;
// Uncomment if this ever matters private boolean likes;
// Created
private long created_utc;
// Link
private String author;
private String domain;
private int num_comments;
private boolean over18;
private boolean is_self;
private String permalink;
private String subreddit;
private String subredditId;
private String title;
private String url;
private String selftext;
private String thumbnail;
private RedditLinkList list;
... Getters and setters
}
和
public class RedditLinkList {
private int id;
public static final RedditLinkList EMPTY = new RedditLinkList();
public Collection<RedditLink> links = new ArrayList<RedditLink>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Collection<RedditLink> getLinks() {
return links;
}
public void setLinks(Collection<RedditLink> links) {
this.links = links;
}
}
我收到以下错误
java.lang.IllegalArgumentException: No fields have a DatabaseField annotation in class rainstudios.kelo.data.model.RedditLinkList
at com.j256.ormlite.table.DatabaseTableConfig.extractFieldTypes(DatabaseTableConfig.java:215)
at com.j256.ormlite.table.DatabaseTableConfig.fromClass(DatabaseTableConfig.java:146)
at com.j256.ormlite.table.TableInfo.<init>(TableInfo.java:53)
at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:151)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:128)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:107)
at com.j256.ormlite.dao.BaseDaoImpl$4.<init>(BaseDaoImpl.java:907)
at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:907)
at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:70)
at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:297)
at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:201)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:128)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:119)
at com.j256.ormlite.dao.BaseDaoImpl$5.<init>(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.DaoManager.doCreateDao(DaoManager.java:359)
at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:129)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:229)
at com.j256.ormlite.table.TableUtils.createTableIfNotExists(TableUtils.java:84)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersisterFactory.createTableIfNotExists(InDatabaseObjectPersisterFactory.java:106)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersisterFactory.initializeTablesIfNeeded(InDatabaseObjectPersisterFactory.java:120)
at com.octo.android.robospice.persistence.ormlite.InDatabaseObjectPersisterFactory.createObjectPersister(InDatabaseObjectPersisterFactory.java:69)
at com.octo.android.robospice.persistence.CacheManager.getObjectPersister(CacheManager.java:183)
at com.octo.android.robospice.persistence.CacheManager.loadDataFromCache(CacheManager.java:68)
at com.octo.android.robospice.request.DefaultRequestRunner.loadDataFromCache(DefaultRequestRunner.java:239)
at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:88)
at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:201)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
以下是我用来生成DatabaseFieldConfig
的代码:
//
// Link
//
List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
DatabaseFieldConfig field1 = new DatabaseFieldConfig("id");
field1.setId(true);
fieldConfigs.add(field1);
DatabaseFieldConfig field2 = new DatabaseFieldConfig("name");
field2.setCanBeNull(false);
fieldConfigs.add(field2);
DatabaseFieldConfig field3 = new DatabaseFieldConfig("url");
fieldConfigs.add(field3);
DatabaseFieldConfig field4 = new DatabaseFieldConfig("title");
fieldConfigs.add(field4);
DatabaseFieldConfig field6 = new DatabaseFieldConfig("author");
fieldConfigs.add(field6);
DatabaseFieldConfig field5 = new DatabaseFieldConfig("subreddit");
fieldConfigs.add(field5);
// @DatabaseField(foreign = true, foreignAutoRefresh = true,
// canBeNull =
// true, columnName = "list_id")
DatabaseFieldConfig field7 = new DatabaseFieldConfig("list");
field7.setForeign(true);
field7.setForeignAutoRefresh(true);
field7.setCanBeNull(true);
field7.setColumnName("list_id");
fieldConfigs.add(field7);
DatabaseTableConfig<RedditLink> link = new DatabaseTableConfig<RedditLink>(
RedditLink.class, fieldConfigs);
//
// List
//
List<DatabaseFieldConfig> fieldListConfigs = new ArrayList<DatabaseFieldConfig>();
DatabaseFieldConfig fieldList1;
fieldList1 = new DatabaseFieldConfig("id");
fieldList1.setColumnName("list_id");
fieldList1.setGeneratedId(true);
fieldListConfigs.add(fieldList1);
DatabaseFieldConfig fieldList2 = new DatabaseFieldConfig("links");
fieldList2.setForeignCollection(true);
fieldList2.setForeignCollectionEager(false);
fieldListConfigs.add(fieldList2);
DatabaseTableConfig<RedditLinkList> list = new DatabaseTableConfig<RedditLinkList>(
RedditLinkList.class, fieldListConfigs);
// Cross references
field7.setForeignTableConfig(list);
fieldList2.setForeignTableConfig(link);
我做错了什么?
注意:我的应用使用ormlite_config.txt
缓存