@Femi is correct that an object can be either a generated identifier or an identifier, but not both. The problem is that ORMLite stores the object, but it must also match the schema with which the database was created.
ORMLite supports the allowGeneratedIdInsert=true parameter for the @DatabaseField annotation, which allows this behavior. This is not supported by some types of databases (e.g. Derby), but it runs on Android / SQLite.
For posterity, you can also create 2 objects that use the same table - one with the generated identifier and without it. You can then insert the generated Dao identifier to get this behavior, and another Tao to accept the id value set by the caller. Here 's another answer talking about this . The problem for you is that it will create many additional DAOs.
The only other solution is not to use an identifier for your purposes. Let the database generate an identifier, and then add an additional field that you use for external purposes. Forcing a database identifier under certain circumstances seems like a bad model to me.
source share