独立的JPA序列

huangapple go评论58阅读模式
英文:

Standalone JPA sequence

问题

通过SQL,可以定义一个序列,例如:CREATE SEQUENCE sequence_name

是否可以使用JPA来定义它?我只知道可以在实体的属性上定义序列。我希望能避免只为了定义一个序列而创建一个实体。

英文:

Through SQL one can define a sequence such as CREATE SEQUENCE sequence_name.

Can it be defined using JPA? I only know of sequences defined on attributes of entities. I'd like to avoid creating an entity just to be able to define a sequence.

答案1

得分: 2

你可以尝试在启动时创建它。
来自这个 文档:
> Spring Boot 可以自动创建您的 DataSource 的模式(DDL 脚本)并初始化它(DML 脚本)。它从标准根类路径位置加载 SQL:schema.sql 和 data.sql

例如,将 SEQUENCE 的创建放入 data.sql 中。

英文:

You can try to create it on start up.
From this documentation:
> Spring Boot can automatically create the schema (DDL scripts) of your DataSource and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema.sql and data.sql

For example put SEQUENCE creation into data.sql

huangapple
  • 本文由 发表于 2020年10月6日 17:04:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64222596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定