Generate short id in ebean prior save entity to database

619 Views Asked by At

I want to get id of entity before it saved to database. If i have EbeanEntity with:

@Id private UUID id; 

and call

Ebean.nextId(EbeanEntity.class);

return value is very complex(ce9d8486-2128-4a66-bef4-4158b6de2c7e). I need short value, like when i use Long or String as Id(1, 2, 3... etc). Ebean.nextId javadoc say "This will only work when a IdGenerator is on this bean type such as a DB sequence or UUID.". If i use Long or String as id, Ebean.nextId returns null. So how can i use "DB sequence" or another way to get short id of item prior save it to database?

1

There are 1 best solutions below

0
On

You just can't.
You have to save your bean into the database before get the ID back.
Something like this

Ebean.save(Object); 
int id = object.id;