2

I have looked for answers but couldn't find any to my problem. I have an existing (complex) database already populated and I wish to integrate it in an Android App. I chose to use GreenDAO and I experimented with the Dao Generator. I checked links like: link and it is not a problem to copy an existing database to assets. My problem is that I still have to write a lot of code to create entities for the model, dao classes to be created/generated.

Example code for generating classes:

Schema schema = new Schema(0, "de.test.app.database");
Entity program = schema.addEntity("Program");
program.addIdProperty();
program.addStringProperty("name");
program.addDateProperty("beginDate");
try {
    DaoGenerator db = new DaoGenerator();
    db.generateAll(schema, "app/src/main/java");
} catch (Exception e) {
    e.printStackTrace();
}

Is there a way to generate the needed model and dao classes after existing database/tables with GreenDao? For example, the way in hibernate you have the possibility to generate the POJO classes from existing tables.

Community
  • 1
  • 1
IoanaC
  • 49
  • 1
  • 7
  • If you are using greenDAO v3, there is no need to use a generator project. You can just add annotations to your existing code. Check [this link](http://greenrobot.org/greendao/documentation/updating-to-greendao-3-and-annotations/). – Allan Pereira Mar 30 '17 at 14:09
  • 2
    If I use greenDAO v3 and I have a database in my assets with a lot of tables, do I need to add all the fields for all the Entities classes that represents the tables? If I have for example a table "User" and I create a class User with the annotation "@Entity", do I also have to add the fields and annotations for all the table's columns? Or is it a way that greenDAO can generate all the necessary classes based on the table User from the database? – IoanaC Mar 30 '17 at 15:08

0 Answers0