2013-07-16 25 views
1

我在下面的結構模型來使用ORMLiteORMlite節能複雜的數據庫

class Item { 
    String name; 
    String number; 
    int id 
    Detail detail; 
    Category category;// getters and setters 
} 

其保存到數據庫裏面和細節和類別類有

​​

所以現在我的問題是我需要創建這種格式的表格

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(); 
    } 
} 

或者我需要有奧利項目表。實際上Item將所有記錄全部保存在一起。在此先感謝

回答

0

您需要創建所有表格,如代碼段中所示。看看更多information on ORMLite annotations的文檔。

+0

謝謝你會嘗試並與我分享我的結果 –

+0

我們是否需要單獨插入所有表或者如果我設置Item類並更新數據庫意味着數據將被插入到它的表中? Dao將自己創建,還是每次都需要創建 –