Objectbox-java: If my entity already has id property, how i use @Id to annotate

Created on 20 Oct 2017  路  3Comments  路  Source: objectbox/objectbox-java

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 ?????

Most helpful comment

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

All 3 comments

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

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

It works. 3Q

Was this page helpful?
0 / 5 - 0 ratings