2

I generated a schema/tables via the DDL that Hibernate generated which was correct:

 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)
)

After that, I tried to generate Liquibase changelog which looks like this:

 <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>

The problem is that if I try to run the liquibase changelog, it translates the XML definition into this:

2020-02-26 16:15:10.779  INFO 8064 --- [main] liquibase.executor.jvm.JdbcExecutor      : CREATE TABLE CAT_COMPONENT.organisation (id NUMBER(19, 0) NOT NULL, archived NUMBER(1, 0), is_in_avaloq_group NUMBER(1, 0) NOT NULL, mdm_uuid VARCHAR2(255 CHAR), name VARCHAR2(255 CHAR), CONSTRAINT organisationPK PRIMARY KEY (id))

2020-02-26 16:15:10.787 INFO 8064 --- [main] liquibase.changelog.ChangeSet : Table organisation created 2020-02-26 16:15:10.787 INFO 8064 --- [main] liquibase.changelog.ChangeSet : ChangeSet classpath:/db/changelog/db.changelog-master.xml::1582733383680-5::blabla (generated) ran successfully in 9ms

As you may have noticed, "generated as identity" is missing, which makes me believe that for whatever reason, the autoIncrement="true" is ignored.

I use Oracle 12.1.0.2 and org.liquibase:liquibase-core 3.8.2. The OJDBC driver is version 19.3.0.0. The gradle properties are:

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}

I've read the Internet, and I know that my Oracle version is compatible with this column type and I don't need to create extra oracle Sequences. Any clue what could be the problem?

Georgi
  • 189
  • 2
  • 12

2 Answers2

2

It seems to be a bug in Liquibase. I just found it here https://liquibase.jira.com/projects/CORE/issues/CORE-3524?filter=allissues&orderby=updated%20DESC&keyword=Oracle

As it states, there is a work-around to add the

 generationType="BY DEFAULT"

at each column definition, where autoIncrement="true" has been used.

Georgi
  • 189
  • 2
  • 12
0

Correct the autoIncrement="true" is ignored due to the missing support on Oracle side for auto incremented columns as seen in the docs from liquienter link description here:

Is column an auto-increment column. Ignored on databases that do not support autoincrement/identity functionality.

You will need to create a sequence for generating the IDs and providing the sequence to the id column when inserting the data i.e. with hibernate:

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XXX_ID_GEN")
  @SequenceGenerator(name = "XXX_ID_GEN", sequenceName = "SEQ_XXX")
  long id;
sudo
  • 747
  • 6
  • 19
  • 3
    Oracle DB has had autoincrement functionality since version 12.1 - that's what the original poster showed with the `create table` syntax `generated as identity` – Christopher Jones Feb 26 '20 at 23:01
  • @ChristopherJones is right, it is supported by my Oracle version. We have some doubts that it's a bug in the documentation/version of the library. I will try to downgrade to liquibase-core 3.5, since 3.6+ expects some extra attribute which is not being generated. – Georgi Feb 27 '20 at 08:41
  • True - thanks for the notification. I was still on the old version of liquibase... – sudo Mar 04 '20 at 10:43