将 oracle 序列与 jpa 一起使用(toplink)

发布于 2024-12-06 04:39:38 字数 1017 浏览 0 评论 0原文

我的 oracle 数据库中有一个序列对象:

create sequence BASE_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 100
increment by 1
nocache;

我将 jpa(toplink) 用于我的 Web 应用程序。我的所有数据库对象都有基类:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)

public class AbstractEntity implements Serializable {
    protected BigDecimal id;

    @javax.persistence.Column(name = "ID")
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BASE_SEQ")
    @SequenceGenerator(name="BASE_SEQ",sequenceName="BASE_SEQ", catalog = "DOF")
    public BigDecimal getId() {
        return id;
    }

此类由某些实体继承。在我启动我的应用程序并将多个实体持久/合并到数据库后,我可以发现它们的 PK 以 51 开头(而不是预期的 100)。

之后,我转到数据库,查看序列对象的 DDL,发现它已更改为:

create sequence BASE_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 101
increment by 1
nocache;

为什么会发生这种情况?我有一些 PK 51、52 ​​... 等的实体,序列以 101 开头。AS

- GlassFish 3.1.1

I have a sequence object in my oracle db:

create sequence BASE_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 100
increment by 1
nocache;

I use jpa(toplink) for my web application. I have base class for all my db objects:

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)

public class AbstractEntity implements Serializable {
    protected BigDecimal id;

    @javax.persistence.Column(name = "ID")
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BASE_SEQ")
    @SequenceGenerator(name="BASE_SEQ",sequenceName="BASE_SEQ", catalog = "DOF")
    public BigDecimal getId() {
        return id;
    }

This class is inherited by some entities. After I start my application, and persist/merge several entities to db, i can find, that theirs' PK starts with 51 (instead of expected 100).

After that, I go to my db, view DDL of my sequence object and see, that it has been changed to:

create sequence BASE_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 101
increment by 1
nocache;

Why so happens? I have some entities with PK 51, 52 ... etc, and sequence starting with 101.

AS - GlassFish 3.1.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只涨不跌 2024-12-13 04:39:38

SequenceGenerator 上的默认 preallocationSize 为 50,它必须与您设置为 1 的序列增量相匹配

。将增量更改为 50(推荐),或将 preallocationSize 更改为 1(这将导致插入性能不佳)。

The default preallocationSize on SequenceGenerator is 50, it must match your sequence increment, which you have set to 1.

Either change your increment to 50 (recommended), or change your preallocationSize to 1 (this will result in poor insert performance).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文