ORMlite保存复杂的数据库

时间:2013-07-16 05:19:34

标签: android ormlite

我在下面的结构中有一个模型,使用ORMLite

将其保存在数据库中
class Item {
    String name;
    String number;
    int id
    Detail  detail;
    Category category;// getters and setters   
}

详细信息和类别类

class Detail {
    String detailName;
    String detailNumber;
    int id 
    ......
}

所以现在我的问题是我需要以这种格式创建表格

public void onCreate(SQLiteDatabase database,
     ConnectionSource connectionSource) {
    try {
        TableUtils.createTable(connectionSource, Item.class);
        TableUtils.createTable(connectionSource, Detail.class);
        TableUtils.createTable(connectionSource, Category.class);
    } catch (SQLException e) {
        Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
        throw new RuntimeException(e);
    } catch (java.sql.SQLException e) {
        e.printStackTrace();
    }
}

或者我需要有oly项目表。实际上,Item将所有记录保存在一起。提前致谢

1 个答案:

答案 0 :(得分:0)

您需要创建所有表格,如代码段中所示。请查看文档以了解更多information on ORMLite annotations