Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:27:04+00:00 2026-06-07T06:27:04+00:00

Here is my code that fails ( it is running within an activity and

  • 0

Here is my code that fails ( it is running within an activity and the DB helper creates the WishList object fine 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 entity. The ID field is auto 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 the ID that is generated in the Database is not the same one that that ORMlite returns in the call below. It returns 1.

 savedID = helper.getWishListDao().create(wl);

The ID in the database is actually 37. Any ideas what I may be doing wrong?
Using version 4.41

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:27:07+00:00Added an answer on June 7, 2026 at 6:27 am

    ORMLite’s Dao.create(...) method does not return the ID of the newly created object but the number of rows in the database that were changed – usually 1. Here are the javadocs for Dao.create(...).

    Create a new row in the database from an object. If the object being created uses DatabaseField.generatedId() then the data parameter will be modified and set with the corresponding id from the database. …
    Returns: The number of rows updated in the database. This should be 1.

    When ORMLite creates the object, the generated ID is then set to the id field afterwards. To find the ID of your new object you get it from the object itself:

    // create returns 1 row changed
    helper.getWishListDao().create(wl);
    // the id field is set on the w1 object after it was created
    savedID = w1.getId();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code that fails: bool Table::win(const Card &card) { for (int i
I am running an asp.net code-behind that creates a string variable which holds a
I cannot get this to work, here is code that I found in another
Here is my Code that I'm trying to run on Mac OS X: import
Here is the code that doesn't work: Enemy.strength = srand((unsigned)time(NULL)) % 10; Enemy.strength is
Here is my code that adds a line to the grid by pressing the
Here is the code that cause me problem since few hours: TabItem newTab =
Here's my code that is not working: print To: ; my $to=<>; chomp $to;
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
I have some code here that uses bitsets to store many 1 bit values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.