objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.4k stars 302 forks source link

If my entity already has id property, how i use @Id to annotate #226

Closed Mister-Seven closed 7 years ago

Mister-Seven commented 7 years ago

if i use @Id to annotate like below:

@Entity public class User {

@Id
public long id;

public String num;

public String phone;

public String password;

public String username;

}

when i first invoke like below:

BoxStore mBoxStore = BaseApplication.instance.getBoxStore();

mUserBox = mBoxStore.boxFor(User.class);

mUserBox.put(mUser); // first insert

then throw Exception below:

java.lang.IllegalArgumentException: ID is higher or equal to internal ID sequence: 24148 (vs. 1). Use ID 0

(zero) to insert new entities.

the 24148 value is from server.

any help ?????

greenrobot commented 7 years ago

Use @Id(assignable = true) - check the docs for details.

greenrobot commented 7 years ago

Feel free to reopen if that is not working for you.

Mister-Seven commented 7 years ago

It works. 3Q