我是一般的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