DB cannot migrate from 8 to 9 on Oracle
Reported by Ben Hood | October 14th, 2011 @ 11:02 AM | in 1.0 (closed)
The upgrade from version 8 to 9 does not seem to work on Oracle:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00955: name is already used by an existing object
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3550) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_21]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_21]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_21]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_21]
at oracle.ucp.jdbc.proxy.StatementProxyFactory.invoke(StatementProxyFactory.java:242) ~[ucp-11.2.0.1.0.jar:11.2.0.1.0]
at oracle.ucp.jdbc.proxy.PreparedStatementProxyFactory.invoke(PreparedStatementProxyFactory.java:124) ~[ucp-11.2.0.1.0.jar:11.2.0.1.0]
at $Proxy9.execute(Unknown Source) ~[na:na]
at net.lshift.hibernate.migrations.TraceableMigrationElement.prepareAndLogAndExecute(TraceableMigrationElement.java:40) ~[hibernate-migrations-0.1-SNAPSHOT.jar:na]
at net.lshift.hibernate.migrations.CreateTableBuilder.createSequences(CreateTableBuilder.java:110) ~[hibernate-migrations-0.1-SNAPSHOT.jar:na]
at net.lshift.hibernate.migrations.CreateTableBuilder.apply(CreateTableBuilder.java:128) ~[hibernate-migrations-0.1-SNAPSHOT.jar:na]
at net.lshift.hibernate.migrations.MigrationBuilder.apply(MigrationBuilder.java:85) ~[hibernate-migrations-0.1-SNAPSHOT.jar:na]
at net.lshift.diffa.kernel.config.AddStoreCheckpointsMigrationStep$.migrate(HibernateConfigStorePreparationStep.scala:455) ~[diffa-kernel-0.9-SNAPSHOT.jar:na]
at net.lshift.diffa.kernel.config.HibernateConfigStorePreparationStep$$anonfun$prepare$2$$anon$2$$anonfun$execute$2.apply(HibernateConfigStorePreparationStep.scala:124) ~[diffa-kernel-0.9-SNAPSHOT.jar:na]
at net.lshift.diffa.kernel.config.HibernateConfigStorePreparationStep$$anonfun$prepare$2$$anon$2$$anonfun$execute$2.apply(HibernateConfigStorePreparationStep.scala:123) ~[diffa-kernel-0.9-SNAPSHOT.jar:na]
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library-2.9.0-1.jar:na]
at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library-2.9.0-1.jar:na]
at net.lshift.diffa.kernel.config.HibernateConfigStorePreparationStep$$anonfun$prepare$2$$anon$2.execute(HibernateConfigStorePreparationStep.scala:123) ~[diffa-kernel-0.9-SNAPSHOT.jar:na]
at org.hibernate.impl.SessionImpl.doWork(SessionImpl.java:1997) ~[hibernate-core-3.6.7-2L.jar:3.6.7-2L]
... 117 common frames omitted
Comments and changes to this ticket
-

Ben Hood November 1st, 2011 @ 02:40 PM
- Milestone set to 1.0
- Milestone order changed from 135 to 0
-

Paul Jones November 8th, 2011 @ 12:48 AM
- Milestone order changed from 4 to 0
There isn't any chance that the migration could have previous half run against the database? I can't see what is special about that create table versus any of the previous that have been run.
-

Ben Hood November 8th, 2011 @ 06:56 AM
Potentially - I think it maybe a case of running the HibernatePreparationTest against an Oracle dev schema, which is what I'd like to do before I close #399 (although it has been merged already, since it fixes something already).
-

Paul Jones November 8th, 2011 @ 07:19 AM
Running that test against Oracle (or many DBs in fact) might be a little fiddly since the .sql files that generate the various states are probably quite HSQLDB/Derby specific.
-

John Wright November 8th, 2011 @ 05:20 PM
Here's a (fiddly) way to reproduce this issue:
To initialize a clean Oracle database to schema version 8:
- Check out and build from commit
0be5974bbf67bd271aca6d6607410a2cd1326832
- Comment out all @DataPoint definitions except for "emptyDb" in
HibernatePreparationTest.scala
- Add a test-scoped dependency on the Oracle driver in
kernel/pom.xml
-
Run the HibernatePreparationTest with the following system properties set:
mvn test -Dtest=HibernatePreparationTest -DforkMode=never -Ddiffa.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect -Ddiffa.jdbc.driver=oracle.jdbc.driver.OracleDriver -Ddiffa.jdbc.url=[oracle jdbc url] -Ddiffa.jdbc.username=[oracle username] -Ddiffa.jdbc.password=[oracle password]
Then, to recreate the migration from schema version 8 to 9:
- Check out and build from commit
43cfcd7ff9d7690275ba03dff045912261e51560
-
Comment out all @DataPoint definitions in HibernatePreparationTest.scala and add the following new one:
@DataPoint def v8 = StartingDatabaseVersion("v8")
-
Comment out the entire block of code after the "Prepare the starting database" comment in the shouldBeAbleToPrepareDatabaseVersion method of HibernatePreparationTest. The block starts like this: "sf.withSessions(s => {"
- Add a test-scoped dependency on the Oracle driver in
kernel/pom.xml as before
- Run the HibernatePreparationTest as before
- Check out and build from commit
0be5974bbf67bd271aca6d6607410a2cd1326832
-

John Wright November 8th, 2011 @ 05:33 PM
It turns out that issue is caused by a bug in CreateTableBuilder. The store_checkpoints table has a multi-column primary key, but the current logic assumes that since the Oracle dialect doesn't support identity columns then sequences must be created. Consequently, it attempts to create a sequence called "domain" after the first column in the primary key, which results in the "name is already used by an existing object" error.
A possible fix for this would be to change the condition on CreateTableBuilder#apply from:
if (!dialect.supportsIdentityColumns()) {to:
if (identityCol && ! dialect.supportsIdentityColumns()) {However, this does not address an edge case in which a table's primary key consists of multiple columns, but one (or more) of them requires a corresponding sequence to be created.
-

-

Paul Jones November 8th, 2011 @ 10:10 PM
- Assigned user set to Paul Jones
- State changed from new to open
I'll take a look at this.
-

Ben Hood November 8th, 2011 @ 10:21 PM
- Assigned user changed from Paul Jones to Ben Hood
- State changed from open to resolved
On the whole, this patch looks good - I'll deploy this against Oracle, and if that goes well, I'll close this ticket.
-

Paul Jones November 8th, 2011 @ 10:25 PM
It probably isn't in the scope of this ticket, but I think we should revise the way that we define sequences. Given that Hibernate supports specifying sequence names for individual columns, we should consider doing the same instead of just basing it on the column name - since wouldn't we see this error appear any time a set of tables had columns called "id" or similar?
-

Ben Hood November 9th, 2011 @ 05:42 AM
- State changed from resolved to closed
- I've tested a fresh migration against a dev instance of Oracle and it was able to migrate from scratch to version 14.
- Raised #412 to cover the follow up.
-> QA+
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
A Real Time Differencing Tool.
People watching this ticket
Tags
Referenced by
-
412
Revise sequence definitions in DB migration
We should look at the way that we define sequences (see #...
-
399
DB cannot migrate from 9 to 10 on Oracle
This was been integration tested against Oracle as part o...