2

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?

cynepnaxa
  • 1,024
  • 1
  • 14
  • 30

1 Answers1

0

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; 
Mornor
  • 3,471
  • 8
  • 31
  • 69