Here is my code that fails (it runs inside the action, and the DB helper creates a WishList object in the database)
DatabaseHelper helper = DatabaseHelper.getInstance( getActivity() ); int savedID = 0; WishList wl = new WishList(); wl.setName("abc"); try { savedID = helper.getWishListDao().create(wl); WishList wl_saved = helper.getWishListDao().queryForId( savedID ); wl_saved.getId(); } catch (SQLException e) { e.printStackTrace(); }
Here is my essence. The ID field is automatically generated.
@DatabaseTable public class WishList { @DatabaseField(generatedId = true) private int id; @DatabaseField( canBeNull = false , unique = true ) private String name; @ForeignCollectionField private ForeignCollection<WishItem> items; ...
What is wrong is that the identifier generated in the database does not match the identifier that ORMlite returns in the call below. It returns 1.
savedID = helper.getWishListDao().create(wl);
The identifier in the database is actually 37. Any ideas what I can do wrong? Using version 4.41
source share