Hello, ddlutils is a great tool,
i try to migrate hsqldb database to apache derby and i have
synchronization problem with autogenerated keys from the old (source) db
and new values from the new db (target db - derby).
Lets say we hawe one row from the parent table
parent table - old db
pk autoincrement - id = 35
parent table- new db
pk autoincrement - id = 2
In this case ddlutils can't insert rows to the tables wich has fk from
parent tables because id value was changed from 35 to 2.
For apache derby i use attached pach for lastInsertedId implementation
Regards
diff -urN
ddlutils/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
ddlutils-modified/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
--- ddlutils/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
2006-01-13 15:17:27.000000000 +0200
+++
ddlutils-modified/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
2006-01-13 15:19:19.000000000 +0200
@@ -66,4 +66,14 @@
{
print("GENERATED BY DEFAULT AS IDENTITY");
}
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String getSelectLastInsertId(Table table)
+ {
+ // supposed one autoincrement filed per table
+ return "select (sc.autoincrementvalue-1) lastid from sys.systables
st, sys.syscolumns sc where st.tablename= '"+table.getName()+"' and
st.tableid=sc.referenceid and sc.autoincrementvalue is not null " ;
+
+ }
}
diff -urN ddlutils/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
ddlutils-modified/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
--- ddlutils/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
2006-01-13 15:17:29.000000000 +0200
+++
ddlutils-modified/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
2006-01-13 15:35:47.000000000 +0200
@@ -981,9 +981,9 @@
lastInsertedIds.next();
- for (int idx = 0; idx < autoIncrColumns.length; idx++)
+ for (int idx = 1; idx <= autoIncrColumns.length; idx++)
{
- Object value =
lastInsertedIds.getObject(autoIncrColumns[idx].getName());
+ Object value = lastInsertedIds.getObject(idx);
PropertyUtils.setProperty(dynaBean,
autoIncrColumns[idx].getName(), value);
}