首页 > 解决方案 > JPA & Ebean DDL,使用@ElementCollection 注解时如何正确生成id?

问题描述

我使用 Ebean 作为我的带有 Play Framework 的 ORM。在我的一些模型中,我使用了@ElementCollection注释。

@ElementCollection
@CollectionTable(name = "tags", joinColumns = @JoinColumn(name = "id"))
@Column(name="tag")
public List<String> tags;

我的问题是,当 Ebean DDL 生成 SQL DDL 来定义我们的表时,使用@ElementCollection注释创建的表使用bigint类型作为其 id 而不是bigserial.

而不是生成,

create table foo (
  id                            bigint not null
  ...
);

应生成以下内容,

create table foo (
  id                            bigserial not null
  ...
);

如何确保所有 id 都是 bigserials?根据我的理解和文档bigint 是无符号的,而不是自动递增的。

标签: playframeworkebean

解决方案


推荐阅读