Liquibase忽略自动增量=";“真的”;对于Oracle数据库
我通过Hibernate生成的DDL生成了一个模式/表,这是正确的:Liquibase忽略自动增量=";“真的”;对于Oracle数据库,oracle,liquibase,liquibase-hibernate,liquibase-sql,Oracle,Liquibase,Liquibase Hibernate,Liquibase Sql,我通过Hibernate生成的DDL生成了一个模式/表,这是正确的: create table cat_component.organisation ( id number(19,0) generated as identity, archived number(1,0), is_in_avaloq_group number(1,0) not null, mdm_uuid varchar2(255 char), name varchar2(255 char
create table cat_component.organisation (
id number(19,0) generated as identity,
archived number(1,0),
is_in_avaloq_group number(1,0) not null,
mdm_uuid varchar2(255 char),
name varchar2(255 char),
primary key (id)
)
之后,我尝试生成Liquibase变更日志,如下所示:
<changeSet author="blabla (generated)" id="1582733383680-5">
<createTable tableName="organisation">
<column autoIncrement="true" name="id" type="NUMBER(19, 0)">
<constraints primaryKey="true" primaryKeyName="organisationPK"/>
</column>
<column name="archived" type="NUMBER(1, 0)"/>
<column name="is_in_avaloq_group" type="NUMBER(1, 0)">
<constraints nullable="false"/>
</column>
<column name="mdm_uuid" type="VARCHAR2(255 CHAR)"/>
<column name="name" type="VARCHAR2(255 CHAR)"/>
</createTable>
</changeSet>
2020-02-26 16:15:10.787信息8064---[main]liquibase.changelog.ChangeSet:已创建表格组织
2020-02-26 16:15:10.787 INFO 8064---[main]liquibase.changelog.ChangeSet:ChangeSet类路径:/db/changelog/db.changelog master.xml::158273383680-5::blabla(已生成)在9毫秒内成功运行
正如您可能已经注意到的,缺少“生成为标识”,而
使我相信无论出于何种原因,自动递增=“true”
被忽略。
我使用Oracle 12.1.0.2和org.liquibase:liquibase core 3.8.2。
OJDBC驱动程序的版本为19.3.0.0。
gradle属性包括:
spring.datasource.url=jdbc:oracle:thin:@//host:1522/SID
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.datasource.username=user
spring.datasource.password=pass
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type=trace
spring.datasource.continue-on-error=true
spring.datasource.platform=oracle
spring.liquibase.url=${spring.datasource.url}
spring.liquibase.user=${spring.datasource.username}
spring.liquibase.password=${spring.datasource.password}
spring.liquibase.url=${spring.datasource.url}
spring.liquibase.user=${spring.datasource.username}
spring.liquibase.password=${spring.datasource.password}
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
spring.liquibase.default-schema=${spring.jpa.properties.hibernate.default_schema}
spring.liquibase.liquibase-schema=${spring.jpa.properties.hibernate.default_schema}
我读过互联网,我知道我的Oracle版本与此列类型兼容,我不需要创建额外的Oracle序列。
有什么问题吗?更正由于Oracle端缺少对自动递增列的支持,因此忽略了
autoIncrement=“true”
,如liqui的文档所示:
列是一个自动递增的列。在不支持的数据库上忽略
支持自动增量/标识功能
在插入数据时,即使用hibernate
,您需要为生成id和向id
列提供序列而进行以下操作:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XXX_ID_GEN")
@SequenceGenerator(name = "XXX_ID_GEN", sequenceName = "SEQ_XXX")
long id;
这似乎是Liquibase中的一个bug。我刚在这里找到的 正如它所说的,添加
generationType="BY DEFAULT"
在每个列定义中,都使用了autoIncrement=“true”。Oracle DB自12.1版起就具有autoIncrement功能-这就是原始海报中显示的
create table
语法生成为identity
@ChristopherJones是正确的,我的Oracle版本支持它。我们怀疑这是库的文档/版本中的一个bug。我将尝试降级到liquibase core 3.5,因为3.6+需要一些未生成的额外属性。我还在用旧版的liquibase。。。
generationType="BY DEFAULT"