getId() method of Entity generates label collisions in DAO_Impl












0















I have noticed no understandable error of generated implementation for my DAO, when using Android Room. First of all I need to mention that I'm making my app as a modification of Android Room with a View.



I have a class for Task:



app/java/com.example.blah/Task.java:



package ...

import ...

@Entity
public class Task {

@PrimaryKey(autoGenerate = true)
@NonNull
@ColumnInfo(name = "id")
protected int _id;

@NonNull
@ColumnInfo(name = "description")
protected String _description;

public Task(@NonNull String description) {
_description = description;

}

public int getId() {
return _id;
}

public String getDescription() {return _description;}
}


When I try to build this code I'm getting compilation error from one of the generated classes:



app/generatedJava/com.example.blah/TaskDAO_Impl.java
package ...



import ...

@SuppressWarnings("unchecked")
public class TaskDAO_Impl implements TaskDAO {
private final RoomDatabase __db;

private final EntityInsertionAdapter __insertionAdapterOfTask;

private final SharedSQLiteStatement __preparedStmtOfDeleteAll;

public TaskDAO_Impl(RoomDatabase __db) {
this.__db = __db;
this.__insertionAdapterOfTask = new EntityInsertionAdapter<Task>(__db) {
@Override
public String createQuery() {
return "INSERT OR ABORT INTO `Task`(`id`,`description`) VALUES (nullif(?, 0),?)";
}

@Override
public void bind(SupportSQLiteStatement stmt, Task value) {
stmt.bindLong(1, value.getId());
if (value.getDescription() == null) {
stmt.bindNull(2);
} else {
stmt.bindString(2, value.getDescription());
}
}
};
this.__preparedStmtOfDeleteAll = new SharedSQLiteStatement(__db) {
@Override
public String createQuery() {
final String _query = "DELETE FROM Task";
return _query;
}
};
}

@Override
public void insert(Task task) {
__db.beginTransaction();
try {
__insertionAdapterOfTask.insert(task);
__db.setTransactionSuccessful();
} finally {
__db.endTransaction();
}
}

@Override
public void deleteAll() {
final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();
__db.beginTransaction();
try {
_stmt.executeUpdateDelete();
__db.setTransactionSuccessful();
} finally {
__db.endTransaction();
__preparedStmtOfDeleteAll.release(_stmt);
}
}

@Override
public LiveData<List<Task>> getAllTasks() {
final String _sql = "SELECT * FROM Task ORDER BY description ASC";
final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
return new ComputableLiveData<List<Task>>() {
private Observer _observer;

@Override
protected List<Task> compute() {
if (_observer == null) {
_observer = new Observer("Task") {
@Override
public void onInvalidated(@NonNull Set<String> tables) {
invalidate();
}
};
__db.getInvalidationTracker().addWeakObserver(_observer);
}
final Cursor _cursor = __db.query(_statement);
try {
final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("id");
final int _cursorIndexOfDescription = _cursor.getColumnIndexOrThrow("description");
final List<Task> _result = new ArrayList<Task>(_cursor.getCount());
while(_cursor.moveToNext()) {
final Task _item;
final String _tmp_description;
_tmp_description = _cursor.getString(_cursorIndexOfDescription);
_item.getId = _cursor.getInt(_cursorIndexOfId);
final String _tmp_1;
_tmp_1 = _cursor.getString(_cursorIndexOfActivationDate);
_item._activationDate = DateStringConverter.intoDate(_tmp_1);
_item.points = _cursor.getInt(_cursorIndexOfPoints);
_result.add(_item);
}
return _result;
} finally {
_cursor.close();
}
}

@Override
protected void finalize() {
_statement.release();
}
}.getLiveData();
}
}


And this line:



_item.getId = _cursor.getInt(_cursorIndexOfId);


Is causing the error:




error: cannot find symbol variable getId




because there is no field getId in class Task. Please note that class mentioned above is not written by me. It's automatically generated by Android Studio.



I wonder why this happen? If I delete function getId() from Task class, everything becomes all right. For the generated code mentioned above, once I delete getId() function, the suspicious line turns into:



_item._id = _cursor.getInt(_cursorIndexOfId);


And everything compiles all right. Can anyone explain it?










share|improve this question



























    0















    I have noticed no understandable error of generated implementation for my DAO, when using Android Room. First of all I need to mention that I'm making my app as a modification of Android Room with a View.



    I have a class for Task:



    app/java/com.example.blah/Task.java:



    package ...

    import ...

    @Entity
    public class Task {

    @PrimaryKey(autoGenerate = true)
    @NonNull
    @ColumnInfo(name = "id")
    protected int _id;

    @NonNull
    @ColumnInfo(name = "description")
    protected String _description;

    public Task(@NonNull String description) {
    _description = description;

    }

    public int getId() {
    return _id;
    }

    public String getDescription() {return _description;}
    }


    When I try to build this code I'm getting compilation error from one of the generated classes:



    app/generatedJava/com.example.blah/TaskDAO_Impl.java
    package ...



    import ...

    @SuppressWarnings("unchecked")
    public class TaskDAO_Impl implements TaskDAO {
    private final RoomDatabase __db;

    private final EntityInsertionAdapter __insertionAdapterOfTask;

    private final SharedSQLiteStatement __preparedStmtOfDeleteAll;

    public TaskDAO_Impl(RoomDatabase __db) {
    this.__db = __db;
    this.__insertionAdapterOfTask = new EntityInsertionAdapter<Task>(__db) {
    @Override
    public String createQuery() {
    return "INSERT OR ABORT INTO `Task`(`id`,`description`) VALUES (nullif(?, 0),?)";
    }

    @Override
    public void bind(SupportSQLiteStatement stmt, Task value) {
    stmt.bindLong(1, value.getId());
    if (value.getDescription() == null) {
    stmt.bindNull(2);
    } else {
    stmt.bindString(2, value.getDescription());
    }
    }
    };
    this.__preparedStmtOfDeleteAll = new SharedSQLiteStatement(__db) {
    @Override
    public String createQuery() {
    final String _query = "DELETE FROM Task";
    return _query;
    }
    };
    }

    @Override
    public void insert(Task task) {
    __db.beginTransaction();
    try {
    __insertionAdapterOfTask.insert(task);
    __db.setTransactionSuccessful();
    } finally {
    __db.endTransaction();
    }
    }

    @Override
    public void deleteAll() {
    final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();
    __db.beginTransaction();
    try {
    _stmt.executeUpdateDelete();
    __db.setTransactionSuccessful();
    } finally {
    __db.endTransaction();
    __preparedStmtOfDeleteAll.release(_stmt);
    }
    }

    @Override
    public LiveData<List<Task>> getAllTasks() {
    final String _sql = "SELECT * FROM Task ORDER BY description ASC";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    return new ComputableLiveData<List<Task>>() {
    private Observer _observer;

    @Override
    protected List<Task> compute() {
    if (_observer == null) {
    _observer = new Observer("Task") {
    @Override
    public void onInvalidated(@NonNull Set<String> tables) {
    invalidate();
    }
    };
    __db.getInvalidationTracker().addWeakObserver(_observer);
    }
    final Cursor _cursor = __db.query(_statement);
    try {
    final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("id");
    final int _cursorIndexOfDescription = _cursor.getColumnIndexOrThrow("description");
    final List<Task> _result = new ArrayList<Task>(_cursor.getCount());
    while(_cursor.moveToNext()) {
    final Task _item;
    final String _tmp_description;
    _tmp_description = _cursor.getString(_cursorIndexOfDescription);
    _item.getId = _cursor.getInt(_cursorIndexOfId);
    final String _tmp_1;
    _tmp_1 = _cursor.getString(_cursorIndexOfActivationDate);
    _item._activationDate = DateStringConverter.intoDate(_tmp_1);
    _item.points = _cursor.getInt(_cursorIndexOfPoints);
    _result.add(_item);
    }
    return _result;
    } finally {
    _cursor.close();
    }
    }

    @Override
    protected void finalize() {
    _statement.release();
    }
    }.getLiveData();
    }
    }


    And this line:



    _item.getId = _cursor.getInt(_cursorIndexOfId);


    Is causing the error:




    error: cannot find symbol variable getId




    because there is no field getId in class Task. Please note that class mentioned above is not written by me. It's automatically generated by Android Studio.



    I wonder why this happen? If I delete function getId() from Task class, everything becomes all right. For the generated code mentioned above, once I delete getId() function, the suspicious line turns into:



    _item._id = _cursor.getInt(_cursorIndexOfId);


    And everything compiles all right. Can anyone explain it?










    share|improve this question

























      0












      0








      0








      I have noticed no understandable error of generated implementation for my DAO, when using Android Room. First of all I need to mention that I'm making my app as a modification of Android Room with a View.



      I have a class for Task:



      app/java/com.example.blah/Task.java:



      package ...

      import ...

      @Entity
      public class Task {

      @PrimaryKey(autoGenerate = true)
      @NonNull
      @ColumnInfo(name = "id")
      protected int _id;

      @NonNull
      @ColumnInfo(name = "description")
      protected String _description;

      public Task(@NonNull String description) {
      _description = description;

      }

      public int getId() {
      return _id;
      }

      public String getDescription() {return _description;}
      }


      When I try to build this code I'm getting compilation error from one of the generated classes:



      app/generatedJava/com.example.blah/TaskDAO_Impl.java
      package ...



      import ...

      @SuppressWarnings("unchecked")
      public class TaskDAO_Impl implements TaskDAO {
      private final RoomDatabase __db;

      private final EntityInsertionAdapter __insertionAdapterOfTask;

      private final SharedSQLiteStatement __preparedStmtOfDeleteAll;

      public TaskDAO_Impl(RoomDatabase __db) {
      this.__db = __db;
      this.__insertionAdapterOfTask = new EntityInsertionAdapter<Task>(__db) {
      @Override
      public String createQuery() {
      return "INSERT OR ABORT INTO `Task`(`id`,`description`) VALUES (nullif(?, 0),?)";
      }

      @Override
      public void bind(SupportSQLiteStatement stmt, Task value) {
      stmt.bindLong(1, value.getId());
      if (value.getDescription() == null) {
      stmt.bindNull(2);
      } else {
      stmt.bindString(2, value.getDescription());
      }
      }
      };
      this.__preparedStmtOfDeleteAll = new SharedSQLiteStatement(__db) {
      @Override
      public String createQuery() {
      final String _query = "DELETE FROM Task";
      return _query;
      }
      };
      }

      @Override
      public void insert(Task task) {
      __db.beginTransaction();
      try {
      __insertionAdapterOfTask.insert(task);
      __db.setTransactionSuccessful();
      } finally {
      __db.endTransaction();
      }
      }

      @Override
      public void deleteAll() {
      final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();
      __db.beginTransaction();
      try {
      _stmt.executeUpdateDelete();
      __db.setTransactionSuccessful();
      } finally {
      __db.endTransaction();
      __preparedStmtOfDeleteAll.release(_stmt);
      }
      }

      @Override
      public LiveData<List<Task>> getAllTasks() {
      final String _sql = "SELECT * FROM Task ORDER BY description ASC";
      final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
      return new ComputableLiveData<List<Task>>() {
      private Observer _observer;

      @Override
      protected List<Task> compute() {
      if (_observer == null) {
      _observer = new Observer("Task") {
      @Override
      public void onInvalidated(@NonNull Set<String> tables) {
      invalidate();
      }
      };
      __db.getInvalidationTracker().addWeakObserver(_observer);
      }
      final Cursor _cursor = __db.query(_statement);
      try {
      final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("id");
      final int _cursorIndexOfDescription = _cursor.getColumnIndexOrThrow("description");
      final List<Task> _result = new ArrayList<Task>(_cursor.getCount());
      while(_cursor.moveToNext()) {
      final Task _item;
      final String _tmp_description;
      _tmp_description = _cursor.getString(_cursorIndexOfDescription);
      _item.getId = _cursor.getInt(_cursorIndexOfId);
      final String _tmp_1;
      _tmp_1 = _cursor.getString(_cursorIndexOfActivationDate);
      _item._activationDate = DateStringConverter.intoDate(_tmp_1);
      _item.points = _cursor.getInt(_cursorIndexOfPoints);
      _result.add(_item);
      }
      return _result;
      } finally {
      _cursor.close();
      }
      }

      @Override
      protected void finalize() {
      _statement.release();
      }
      }.getLiveData();
      }
      }


      And this line:



      _item.getId = _cursor.getInt(_cursorIndexOfId);


      Is causing the error:




      error: cannot find symbol variable getId




      because there is no field getId in class Task. Please note that class mentioned above is not written by me. It's automatically generated by Android Studio.



      I wonder why this happen? If I delete function getId() from Task class, everything becomes all right. For the generated code mentioned above, once I delete getId() function, the suspicious line turns into:



      _item._id = _cursor.getInt(_cursorIndexOfId);


      And everything compiles all right. Can anyone explain it?










      share|improve this question














      I have noticed no understandable error of generated implementation for my DAO, when using Android Room. First of all I need to mention that I'm making my app as a modification of Android Room with a View.



      I have a class for Task:



      app/java/com.example.blah/Task.java:



      package ...

      import ...

      @Entity
      public class Task {

      @PrimaryKey(autoGenerate = true)
      @NonNull
      @ColumnInfo(name = "id")
      protected int _id;

      @NonNull
      @ColumnInfo(name = "description")
      protected String _description;

      public Task(@NonNull String description) {
      _description = description;

      }

      public int getId() {
      return _id;
      }

      public String getDescription() {return _description;}
      }


      When I try to build this code I'm getting compilation error from one of the generated classes:



      app/generatedJava/com.example.blah/TaskDAO_Impl.java
      package ...



      import ...

      @SuppressWarnings("unchecked")
      public class TaskDAO_Impl implements TaskDAO {
      private final RoomDatabase __db;

      private final EntityInsertionAdapter __insertionAdapterOfTask;

      private final SharedSQLiteStatement __preparedStmtOfDeleteAll;

      public TaskDAO_Impl(RoomDatabase __db) {
      this.__db = __db;
      this.__insertionAdapterOfTask = new EntityInsertionAdapter<Task>(__db) {
      @Override
      public String createQuery() {
      return "INSERT OR ABORT INTO `Task`(`id`,`description`) VALUES (nullif(?, 0),?)";
      }

      @Override
      public void bind(SupportSQLiteStatement stmt, Task value) {
      stmt.bindLong(1, value.getId());
      if (value.getDescription() == null) {
      stmt.bindNull(2);
      } else {
      stmt.bindString(2, value.getDescription());
      }
      }
      };
      this.__preparedStmtOfDeleteAll = new SharedSQLiteStatement(__db) {
      @Override
      public String createQuery() {
      final String _query = "DELETE FROM Task";
      return _query;
      }
      };
      }

      @Override
      public void insert(Task task) {
      __db.beginTransaction();
      try {
      __insertionAdapterOfTask.insert(task);
      __db.setTransactionSuccessful();
      } finally {
      __db.endTransaction();
      }
      }

      @Override
      public void deleteAll() {
      final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();
      __db.beginTransaction();
      try {
      _stmt.executeUpdateDelete();
      __db.setTransactionSuccessful();
      } finally {
      __db.endTransaction();
      __preparedStmtOfDeleteAll.release(_stmt);
      }
      }

      @Override
      public LiveData<List<Task>> getAllTasks() {
      final String _sql = "SELECT * FROM Task ORDER BY description ASC";
      final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
      return new ComputableLiveData<List<Task>>() {
      private Observer _observer;

      @Override
      protected List<Task> compute() {
      if (_observer == null) {
      _observer = new Observer("Task") {
      @Override
      public void onInvalidated(@NonNull Set<String> tables) {
      invalidate();
      }
      };
      __db.getInvalidationTracker().addWeakObserver(_observer);
      }
      final Cursor _cursor = __db.query(_statement);
      try {
      final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("id");
      final int _cursorIndexOfDescription = _cursor.getColumnIndexOrThrow("description");
      final List<Task> _result = new ArrayList<Task>(_cursor.getCount());
      while(_cursor.moveToNext()) {
      final Task _item;
      final String _tmp_description;
      _tmp_description = _cursor.getString(_cursorIndexOfDescription);
      _item.getId = _cursor.getInt(_cursorIndexOfId);
      final String _tmp_1;
      _tmp_1 = _cursor.getString(_cursorIndexOfActivationDate);
      _item._activationDate = DateStringConverter.intoDate(_tmp_1);
      _item.points = _cursor.getInt(_cursorIndexOfPoints);
      _result.add(_item);
      }
      return _result;
      } finally {
      _cursor.close();
      }
      }

      @Override
      protected void finalize() {
      _statement.release();
      }
      }.getLiveData();
      }
      }


      And this line:



      _item.getId = _cursor.getInt(_cursorIndexOfId);


      Is causing the error:




      error: cannot find symbol variable getId




      because there is no field getId in class Task. Please note that class mentioned above is not written by me. It's automatically generated by Android Studio.



      I wonder why this happen? If I delete function getId() from Task class, everything becomes all right. For the generated code mentioned above, once I delete getId() function, the suspicious line turns into:



      _item._id = _cursor.getInt(_cursorIndexOfId);


      And everything compiles all right. Can anyone explain it?







      android dao






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 18:56









      AsmoxAsmox

      358




      358
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268423%2fgetid-method-of-entity-generates-label-collisions-in-dao-impl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268423%2fgetid-method-of-entity-generates-label-collisions-in-dao-impl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation