我希望在保存到数据库之前获取实体的id。如果我有EbeanEntity:
@Id private UUID id;
并致电
Ebean.nextId(EbeanEntity.class);
返回值非常复杂(ce9d8486-2128-4a66-bef4-4158b6de2c7e)。我需要短值,就像我使用Long或String作为Id(1,2,3 ......等)。 Ebean.nextId javadoc说“只有在IdGenerator处于此bean类型时才会起作用,例如DB序列或UUID。”。如果我使用Long或String作为id,则Ebean.nextId返回null。 那么我怎样才能使用“数据库序列”或其他方式获取项目的短ID,然后将其保存到数据库?
答案 0 :(得分:0)
你只是无法。
在获取ID之前,您必须将bean保存到数据库中。
像这样的东西
Ebean.save(Object);
int id = object.id;