Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoincrement not work #441

Closed
Gvardia opened this issue Sep 9, 2016 · 9 comments
Closed

autoincrement not work #441

Gvardia opened this issue Sep 9, 2016 · 9 comments

Comments

@Gvardia
Copy link

Gvardia commented Sep 9, 2016

Hi, i set

@Id(autoincrement = true)
private long   id;

And still get

09-09 17:53:16.785 21412-21850/works.idna.iddna E/dao.insert(week): android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: WEEK._id (code 1555)
in dao.insert(week)
@greenrobot-team
Copy link
Collaborator

greenrobot-team commented Sep 19, 2016

Try to use Long instead of long.

   @Id(autoincrement = true)
   private Long id;

And maybe do not set an 'id' before inserting (so id == null).
-ut

@greenrobot-team greenrobot-team self-assigned this Sep 19, 2016
@greenrobot-team
Copy link
Collaborator

No response. Closing. -ut

@greenrobot-team greenrobot-team removed their assignment Apr 11, 2017
@MrRoshan
Copy link

I meet the same issue, doesn't set id before inserting, use Long instead of long works. Can't use long property for id?

@greenrobot-team
Copy link
Collaborator

greenrobot-team commented Apr 24, 2017

@MrRoshan Yes, you can use long. But then you have to take care of assigning IDs yourself (as the default for long is 0 and greenDAO does not know whether this means no ID or ID == 0; if you use Long greenDAO assumes ID == null means no ID). -ut

@danmuf
Copy link

danmuf commented May 12, 2017

I had the same problem and set type Long to ID. But now I get an error in the files which are build:

IdeaDao ->  
@Override
public boolean hasKey(Idea entity) {
        return entity.getIdeaID() != null;
 }

I get the error: incomparable types: long and <null> 

I tried to clean and rebuild the project, but it doesn't work. Do you have an idea?

@greenrobot-team
Copy link
Collaborator

@danmuf Check that the return type for entity.getIdeaID() is Long. -ut

@danmuf
Copy link

danmuf commented May 15, 2017

I fixed this problem by deleting all the @generated methods in the classes for the db. After rebuilding the project there was no error (probably a little bug concerning changing the type of a property?).

@sgatade
Copy link

sgatade commented Dec 6, 2017

Long works after updating Constructor/Getter & Setters. Thanks!

@abdussamad123
Copy link

@MrRoshan Yes, you can use long. But then you have to take care of assigning IDs yourself (as the default for long is 0 and greenDAO does not know whether this means no ID or ID == 0; if you use Long greenDAO assumes ID == null means no ID). -ut

i'm using Long type for autoincrement id and not inserting id but still its showing UNIQUE constraint failed ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants