我有这些实体:
public class Category {
private Long id;
private String name;
private Integer color;
}
public class Item {
private Long id;
private String name;
private String groupType;
private Category category;
}
我应该如何建模greenDAO以在Item对象中包含Category?
修改
生成器代码:
public class GreenDaoGenerator {
public static final String DEFAULT_PACKAGE = "xxxxx";
public static void main(String[] args) throws Exception {
Schema schema = new Schema(1, DEFAULT_PACKAGE + ".entity");
schema.setDefaultJavaPackageDao(DEFAULT_PACKAGE + ".dao");
addCategory(schema);
addItem(schema);
DaoGenerator daoGenerator = new DaoGenerator();
daoGenerator.generateAll(schema, "Generated Files");
}
private static void addItem(Schema schema) {
Entity entity = schema.addEntity("Item");
entity.addIdProperty();
entity.addStringProperty("Name");
entity.addStringProperty("GroupType");
Property IdProperty = entity.addLongProperty("categoryId").getProperty();
entity.addToOne(schema.getEntities().get(0), IdProperty);
}
private static void addCategory(Schema schema) {
Entity entity = schema.addEntity("Category");
entity.addIdProperty();
entity.addStringProperty("Name");
entity.addIntProperty("Color");
}
}
我在你回答后做了,请看看我是否正确地做了。感谢。
答案 0 :(得分:1)
您必须使用GreenDao Relations,将a1 = 'aaaaa'
实体映射到Item
实体。
以下是一个示例(其中Category
和item
是您的greenDAO生成器代码中的实体):
category