Prakash P
Prakash P

Reputation: 4066

Start ID value from a user defined number in Ebean, Play-framework 2.5.4 java

I am using Play-framework 2.5.4 (Java). I am using Ebean as ORM.

This is My Model class :

    @Entity
    public class MyModel extends Model
    {
        @Id
        @GeneratedValue()
        public Long ID;
   }

What I am trying to achieve is,

The default value of ID generating now is 1,2,3,4 and so on.

How can I achieve this?

Upvotes: 1

Views: 268

Answers (1)

Evers
Evers

Reputation: 1908

You could implement a custom UID generator like http://ebean-orm.github.io/docs/mapping/jpa/id.

public class ModUuidGenerator implements IdGenerator {

  @Override
  public Object nextValue() {
    return 9999999l + ModUUID.newShortId();
  }

  @Override
  public String getName() {
    return "shortUid";
  }
}

Always incrementing by 1 can cause concurrency issues, but this does force that each id > 9999999l.

Upvotes: 2

Related Questions