greenDao generator is not generating certain variables in auto generated classes

StackOverflow https://stackoverflow.com/questions/18384451

  •  26-06-2022
  •  | 
  •  

Question

Below is my schema generation code, Two variables (storeIdForSurvey & questionIdForAnswer) are not being auto generated in the model class( Survey & Question), though they are present the in auto generated dao classes (SurveyDao & QuestionDao).

Object Oriented description of the domain is as : User has Store, Store has Survey,Survey has FollowupItems, Survey has Category, Category has Question, Question has History, Question has Answer.

private static void addUser(Schema schema) {

    //User

    Entity user = schema.addEntity("User");

    user.addIdProperty();

    user.addStringProperty("districtId");

    user.addStringProperty("employeeId");

    user.addStringProperty("name");

    user.addStringProperty("sessionToken");

    user.addStringProperty("userId");



    //Store

    Entity store = schema.addEntity("Store");

    // foreign key

    Property userIdForStore = store.addLongProperty("userIdForStore").getProperty();

    store.addToOne(user, userIdForStore);

    user.addToMany(store, userIdForStore);



    store.addIdProperty();

    store.addStringProperty("storeId");

    store.addStringProperty("address");

    store.addStringProperty("city");

    store.addStringProperty("storeName");

    store.addStringProperty("state");

    store.addStringProperty("zip");

    store.addStringProperty("storeManagerName");

    store.addBooleanProperty("isSurveyHistoryAvailable");      





    //Survey

    Entity survey = schema.addEntity("Survey");

    //foreign key

    Property storeIdForSurvey = survey.addLongProperty("storeIdForSurvey").getProperty();

    survey.addToOne(store, storeIdForSurvey); // one store can have one survey at a time

    store.addToOne(survey, storeIdForSurvey);



    survey.addIdProperty();

    survey.addStringProperty("surveyId");

    survey.addStringProperty("dmSignImagePath");

    survey.addStringProperty("dmSignImageName");

    survey.addStringProperty("smSignImagePath");

    survey.addStringProperty("smSignImageName");

    survey.addStringProperty("startlatitude");

    survey.addStringProperty("startlongitude");

    survey.addStringProperty("submitLatitude");

    survey.addStringProperty("submitLongitude");

    survey.addStringProperty("acknowledgedBy");

    survey.addStringProperty("deliveredBy");

    survey.addStringProperty("name");

    survey.addStringProperty("createdBy");

    survey.addStringProperty("description");

    survey.addStringProperty("storeId");

    survey.addStringProperty("districtManager");



    survey.addDateProperty("startDate");

    survey.addDateProperty("submitDate");

    survey.addDateProperty("syncDate");

    survey.addDateProperty("createdDate");

    survey.addDateProperty("actionItemAssignDate");

    survey.addDateProperty("actionItemDueDate");

    survey.addDoubleProperty("score");





    //FolloupItems

    Entity followupItem = schema.addEntity("FollowupItem");



    //foreign key

    Property surveyIdForFollowupItem = followupItem.addLongProperty("surveyIdForFollowupItem").getProperty(); 

    followupItem.addToOne(survey, surveyIdForFollowupItem);

    survey.addToMany(followupItem, surveyIdForFollowupItem);



    followupItem.addIdProperty();

    followupItem.addStringProperty("assignedTo");

    followupItem.addStringProperty("comment");

    followupItem.addStringProperty("photoName");

    followupItem.addStringProperty("photoURL");

    followupItem.addDateProperty("assignedDate");

    followupItem.addDateProperty("dueDate");

    followupItem.addDateProperty("expeireDate");





    //Category



    Entity category = schema.addEntity("Category");



    //foreign key

    Property surveyIdForCategory = category.addLongProperty("surveyIdForCategory").getProperty();

    category.addToOne(survey, surveyIdForCategory);

    survey.addToMany(category, surveyIdForCategory);



    category.addIdProperty();

    category.addStringProperty("categoryId");

    category.addStringProperty("name");

    category.addStringProperty("weight");

    category.addStringProperty("surveyId");

    category.addDoubleProperty("totalScore");

    category.addIntProperty("sortOrder");

    category.addBooleanProperty("completionStatus");

    category.addBooleanProperty("hasActionItem");



    //Question

        Entity question = schema.addEntity("Question");



        //foreign key

        Property categoryIdForQuestion = question.addLongProperty("categoryIdForQuestion").getProperty();

        question.addToOne(category, categoryIdForQuestion);

        category.addToMany(question, categoryIdForQuestion);



        question.addIdProperty();

        question.addStringProperty("questionId");

        question.addDateProperty("startDate");

        question.addDateProperty("endDate");

        question.addStringProperty("statement");

        question.addStringProperty("type");

        question.addStringProperty("weight");

        question.addStringProperty("surveyCategoryName");

        question.addIntProperty("displayOrder");

        question.addBooleanProperty("naFlag");

        question.addBooleanProperty("isRequired");



      //Question History

    Entity questionHistory = schema.addEntity("questionHistory");



    //foreign key

    Property questionIdForQuestionHistory =  questionHistory.addLongProperty("questionIdForQuestionHistory").getProperty();

    questionHistory.addToOne(store, questionIdForQuestionHistory);

    question.addToMany(questionHistory, questionIdForQuestionHistory);



    questionHistory.addIdProperty();

    questionHistory.addStringProperty("questionId");

    questionHistory.addStringProperty("secondLastHistory");

    questionHistory.addStringProperty("lastHistory");





        //Answer

        Entity answer = schema.addEntity("Answer");



        //foreign key

        Property questionIdForAnswer = answer.addLongProperty("questionIdForAnswer").getProperty();

        question.addToOne(answer, questionIdForAnswer);

        answer.addToOne(question, questionIdForAnswer);



        answer.addIdProperty();

        answer.addStringProperty("projectType");

        answer.addStringProperty("assignedTo");

        answer.addStringProperty("comment");

        answer.addStringProperty("photoUrl");

        answer.addStringProperty("photoNmae");

        answer.addStringProperty("selectedOption");

        answer.addDateProperty("assignedDate");

        answer.addDateProperty("dueDate");

        answer.addDateProperty("expireDate");

        answer.addDoubleProperty("score");



    }
Was it helpful?

Solution

please read the documentation carefully:

public ToOne addToOne(Entity target, Property fkProperty)

Adds a to-one relationship to the given target entity using the given given foreign key property (which belongs to this entity).

This means the following statement is correct:

Property storeIdForSurvey = survey.addLongProperty("storeIdForSurvey").getProperty();
survey.addToOne(store, storeIdForSurvey); 

but the next statement is incorrect since the Property storeIdForSurvey is not member of the Entity store:

store.addToOne(survey, storeIdForSurvey);

Try to use this statement instead:

store.addToOneWithoutProperty("Survey", survey, "storeIdForSurvey");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top