我是一般的Android開發新手,我甚至從來沒有使用過greenDAO。但是花了很多時間在我的生成器類(在我的實體模型的地方)工作之後,我終於能夠生成一些與GitHub上給出的示例類似的東西。greenDAO發生器給控制檯錯誤,沒有意義
import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
public class simbalDAOgen {
public static void main(String[] args) throws Exception {
Schema schema = new Schema(1, "com.bkp.simbal"); //Schema(Int version, String package name)
addCBTrans(schema); //Add the entities to the schema
new DaoGenerator().generateAll(schema, "../Simbal/src-gen", "../Simbal/src-test"); //Generate DAO files
}
private static void addCBTrans(Schema schema){
Entity checkbook = schema.addEntity("Checkbook");
checkbook.addIdProperty();
checkbook.addStringProperty("name").notNull();
checkbook.addDateProperty("dateModified");
checkbook.addStringProperty("balance"); // Use a string property because BigDecimal type should be used for currency
Entity transaction = schema.addEntity("Transaction");
transaction.setTableName("TRANS"); // "TRANSACTION" is a reserved SQLite keyword
transaction.addIdProperty();
transaction.addStringProperty("name");
transaction.addStringProperty("category");
Property transDate = transaction.addDateProperty("date").getProperty();
transaction.addStringProperty("amount"); // Again use string for BigDecimal type
transaction.addStringProperty("notes");
Property cbName = transaction.addStringProperty("cb").notNull().getProperty(); //What checkbook the transaction is in
ToMany cbToTrans = checkbook.addToMany(transaction, cbName); //Actually ties the transactions to their correct checkbooks
cbToTrans.setName("Transactions");
cbToTrans.orderAsc(transDate);
}
}
我然後跑的代碼作爲一個Java應用程序生成吾道文件,就像在greenDAO的文件說要。成功生成的文件,但我沒有得到在Eclipse的控制檯這一行:
Warning to-one property type does not match target key type: ToMany 'Transactions' from Checkbook to Transaction
我真的不知道,如果我需要關心的,因爲生成的文件。但是我不明白的是,當我使用「一對多」關係時,爲什麼會提到「一對一」關係,正如我的代碼中所見。 (在支票簿實體中可以有許多交易實體,並且我打算使用每個支票簿實體的名稱來將交易與它結合)。
我是否需要返回並修復部分代碼?請問我是否需要澄清任何事情,並感謝您的時間!
你是對的,這是一個相當模糊的消息。謝謝你的問題和答案! – BeccaP 2015-08-04 22:35:22