我正在尝试使用这些模型建立数据库
报告模型
@DatabaseTable(tableName = "report")
public class Report {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(columnName = "client_name")
private String client;
@ForeignCollectionField(maxEagerLevel = 2, eager = true)
private Collection<Product> productList;
产品型号
@DatabaseTable(tableName = "product")
public abstract class Product implements Comparable<Product> {
@DatabaseField(generatedId = true)
private int id;
@DatabaseField(foreign = true)
private Report report;
@DatabaseField(columnName = "instance")
private String instance;
@DatabaseField(columnName = "product_type")
private String productType;
所以我能够成功地插入表格中, 但是尝试时:
List<Report> reports = reportDao.queryBuilder().where().eq("client_name", clientName).query();
我有例外
Could not create object for class model.product.Product
这是有道理的,因为Product是抽象的,但是有没有一种方法可以使用Product界面中的“ Instance”属性(指示产品是哪种产品的实现)来在运行查询时创建适当的对象?
谢谢