Liquibase-generated SQL gives ORA-01735 error - oracle

I am running the following changeset on an Oracle 12 database (the latest official docker image). When the changeset is executed, I get a SQL error:
Error: ORA-01735: invalid ALTER TABLE option
[Failed SQL: ALTER TABLE TEST.LANGUAGE ADD CONSTRAINT SYS_C0010528 PRIMARY KEY (ID) USING INDEX TEST.SYS_C0010528]
I generated the changeset from an existing Oracle database schema using Liquibase tools, with minor alterations.
Does liquibase not support Oracle 12?
How do I configure liquibase to generate Oracle 12-compatible SQL?
Is this a settings issue, or a bug in Liquibase?
Details:
It looks like Oracle doesn't accept the qualifier for the index name in the USING INDEX statement. The following revised SQL seems to work as intended:
ALTER TABLE TEST.LANGUAGE ADD CONSTRAINT SYS_C0010528 PRIMARY KEY (ID) USING INDEX SYS_C0010528
Here is the changeset definition:
<changeSet author="rmorrise (generated)" id="1507039841670-7">
<preConditions onFail="MARK_RAN">
<not>
<primaryKeyExists tableName="LANGUAGE"/>
</not>
</preConditions>
<createIndex indexName="SYS_C0010528" tableName="LANGUAGE" unique="true">
<column name="ID"/>
</createIndex>
<addPrimaryKey columnNames="ID" constraintName="SYS_C0010528" forIndexName="SYS_C0010528" tableName="LANGUAGE"/>
</changeSet>
Update:
I fixed the <addPrimaryKey> entries by replacing them with <sql> tags, but I got the same error on <addUniqueConstraint> with forIndexName.
Here is the generated SQL to create the index. It appears to be created in the same schema.
CREATE UNIQUE INDEX TEST.UK46FCA532E38E4F92860631AA28CB ON TEST.MESSAGE_ROLE(TEMPLATE_ID, LABEL);
ALTER TABLE TEST.MESSAGE_ROLE ADD CONSTRAINT UK46FCA532E38E4F92860631AA28CB UNIQUE (TEMPLATE_ID, LABEL) USING INDEX TEST.UK46FCA532E38E4F92860631AA28CB;
To answer Alex's question about the use of system object names: The schema was originally generated by hbm2ddl and migrated to liquibase using generateChangelog.
A query to dba_objects confirms that the OWNER is TEST.

I had a similar problem and as I was reading this topic I see that we both named our schema "TEST".
I changed the schema's name and it worked immediatly.

Related

Spring Boot: How do I specify execute order of different schema.sql files?

I have created a table that has a foreign key constraint on spring-session-jdbc's spring_session table. The main motivation is that spring-session would delete the rows so that it would cascade and delete entries associated with the actual session. It became a "only works on my machine" problem because only me have had the table already in place when I start the development server. It would only work if others comment out the table first, initialize the server, then revert and do it again. Otherwise, nested exception is java.sql.SQLException: Failed to open the referenced table 'spring_session'.
I think the solution is to specify the run order of (or dependencies between) the initialization sql files. I cannot find that setting after some searching, so I am here.
schema.sql:
drop table if exists foo;
create table if not exists foo (
sid char(36) not null,
foreign key (sid) references spring_session (session_id) on delete cascade,
-- other columns and constraints
);
Possible workarounds:
Workaround #1: put an alter table add constraint statement like this in data.sql.
Workaround #2: grab spring-session-jdbc's schema.sql and put it into my schema.sql, then set spring.session.jdbc.initialize-schema=never in application.properties.
U can try flyway,it can manage your init sql files by giving them a version number. And it can record which sql have been executed, so if add another sql files, it will excute the sql you added, pass the others that have been executed.

Is Auto_Increment supported in Oracle using Liquibase

I want to add an auto_increment column in an oracle database using liquibase script.
I have tried using the auto_increment attribute in liquibase :
<column name="SUPPLEMENT_ID" type="INTEGER" autoIncrement="true" >
<constraints primaryKey="true"></constraints>
</column>
If oracle supports auto_increment, how can I achieve it using liquibase scripts?
IDENTITY columns are introduced in oracle 12c which allows users to create auto increment columns
But if you are using older versions you have to model the column with sequence and triggers as there is no such option as auto_increment or identity.
Please see this answer on how to do it in both cases
https://stackoverflow.com/a/11296469/8330426
According to #APC's comment under the question, Liquibase supports Oracle auto increment since version 3.4.0. See https://liquibase.jira.com/browse/CORE-1731.

Liquibase duplicate changeSet not failing as expected

So I have an Oracle database which I am updating in liquibase... in the process of testing my DB build system, I created a new change which is identical in content to an older change with a different ID. Both are adding a column with the same name, using SQL. I would expect the 2nd to fail, since it would attempt to create a column which already exists, but the liquibase command updateTestingRollback reports:
Liquibase 'updateTestingRollback' Successful
Any ideas what the potential cause may be?
<changeSet id="2" author="anonymous" failOnError="true">
<sql>ALTER TABLE person ADD (col_a VARCHAR(1));</sql>
<rollback>ALTER TABLE person DROP COLUMN col_a;</rollback>
</changeSet>
<changeSet id="3" author="anonymous" failOnError="true">
<sql>ALTER TABLE person ADD (col_a VARCHAR(1));</sql>
<rollback>ALTER TABLE person DROP COLUMN col_a;</rollback>
</changeSet>
You might try running with the --logLevel=debug flag added to make sure, but my guess is that oracle is not returning an error code when the sql for the second change is applied. if you use the <sql> tag rather than more specific change type tags (i.e. the <addColumn> tag), liquibase has a more difficult time detecting problems.

Schema name prefix issue in SQL query

I have WMADMIN schema. This schema is configured as connection credential in websphere datasource.
I have table in other schema/user OCS_JOBS. But the problem is my application looking for the table in WMADMIN schema.
It looks i need to prefix schemaname OCS_JOBS in SQL query to run them.
Is there any other way to run the SQL query the table which is in other user/schema without prefixing the other schema name
You can create a SYNONYM see it here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7001.htm

oracle 11g hibernate problem

I am changing my database from PostgreSQL to Oracle 11g. I am using hibernate 3.0 with Java and Struts.
Everything is working fine with PostgreSQL.
I have changed following in hibernate.cfg.xml file.
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.connection.url">jdbc:Oracle:thin:#192.168.1.1:1521/mydb</property>
<property name="hibernate.connection.username">my_user</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
Everything else is same as that was in Postgresql.
I am using ojdbc5.jar
Now when I run my page it gives me following error.
ORA-00903: invalid table name
Can any one help me regarding the matter?
Thanks.
dpbradley is probably correct, however, I just ran into the following problem with 11g and hibernate:
- oracle 11g will let you define a table with a name larger than 30 characters
- however, you can't actually refer to that table in a SQL statement because its name is too long.
Hibernate auto generated DDL does not seem care or warn when it generates the DDL
It's most likely one of two cases:
You are connecting as a user other than the owner of the table and can't resolve the name.
There is a problem with case sensitivity in either the reference to the table name in the code or its actual name.
If you are not the owner of the table (but have grants to access it!), you'll need to either have an Oracle synonym that translates a reference to MYTABLE into THE_ACTUAL_OWNER.MYTABLE, or reference the schema qualifier directly in your code.
The second case is less likely, but sometimes table creation scripts will create objects in oracle with double quotes around the object name, which will allow creation of mixed-case identifier - CREATE TABLE "myTable" will create the mixed case identifier which then must be referenced by the mixed-case string.
To provide us with further info, connect with some sort of ad-hoc SQL tool as the same user as your application and post the results of:
select owner, table_name from all_tables where table_name = 'theNameOfTheTableOfinterest';

Resources