I think I know what the problem is.
It's in the class org/hibernate/cfg/Configuration.java. In the method
iterateGenerators, it gathers the generators in a TreeMap with the surrogate key table name as the map key. If you reuse the same table name for multiple surrogate key definitions, the map only saves the last one put into its collection because, as you know, maps cannot have duplicate keys. So the result is, the final collection contains 1 element with the table name and only the last columnName it saw. This generates the create SQL with only one columnName as such:
Code:
create table NextKey ( nextbackinstockemailid integer )
INSERT INTO NEXTKEY VALUES(0)
I don't know if there are any configurations to change this behavior, but I have managed to hacked the 3.2.6.ga source to fix the problem for us. It's not pretty, but it works. I know your not suppose to change interfaces but, like I said, it works for us.
I'm not 100% sure how to create patches but here is an attempt.....
org.hibernate.cfg.Configuration.java patch
Code:
--- /cygdrive/c/temp/hibernate-3.2/src/org/hibernate/cfg/Configuration.java 2008-01-24 20:34:42.000000000 -0500
+++ Configuration.java 2008-02-12 21:23:04.363924500 -0500
@@ -722,7 +722,14 @@
);
if ( ig instanceof PersistentIdentifierGenerator ) {
- generators.put( ( (PersistentIdentifierGenerator) ig ).generatorKey(), ig );
+ PersistentIdentifierGenerator pidg = (PersistentIdentifierGenerator) ig;
+ if (generators.containsKey(pidg.generatorKey())) {
+ PersistentIdentifierGenerator old_pidg = (PersistentIdentifierGenerator)generators.get(pidg.generatorKey());
+ old_pidg.setColumnName(old_pidg.getColumnName() + " integer, " + pidg.getColumnName());
+ generators.put(pidg.generatorKey(), old_pidg);
+ } else {
+ generators.put( ( (PersistentIdentifierGenerator) ig ).generatorKey(), ig );
+ }
}
}
org.hibernate.id.PersistentIdentifierGenerator.java patch
Code:
--- /cygdrive/c/temp/hibernate-3.2/src/org/hibernate/id/PersistentIdentifierGenerator.java 2005-04-26 02:37:54.000000000 -0400
+++ PersistentIdentifierGenerator.java 2008-02-12 21:33:26.457674500 -0500
@@ -71,6 +71,8 @@
static final Log SQL = LogFactory.getLog("org.hibernate.SQL");
+ public String getColumnName();
+ public void setColumnName(String columnName);
}
org.hibernate.id.TableGenerator.java patch
Code:
--- /cygdrive/c/temp/hibernate-3.2/src/org/hibernate/id/TableGenerator.java 2007-03-19 18:06:46.000000000 -0400
+++ TableGenerator.java 2008-02-12 21:22:19.817049500 -0500
@@ -97,9 +97,14 @@
public String[] sqlCreateStrings(Dialect dialect) {
+ String[] numOfColumns = columnName.split(",");
+ String cols = "0";
+ for (int x=1; x<numOfColumns.length; x++) {
+ cols += ",0";
+ }
return new String[] {
dialect.getCreateTableString() + " " + tableName + " ( " + columnName + " " + dialect.getTypeName(Types.INTEGER) + " )",
- "insert into " + tableName + " values ( 0 )"
+ "insert into " + tableName + " values ( " + cols + " )"
};
}
@@ -167,4 +172,13 @@
while (rows==0);
return new Integer(result);
}
+
+ public void setColumnName(String columnName) {
+ this.columnName = columnName;
+ }
+
+ public String getColumnName() {
+ return this.columnName;
+ }
+
}
[/code]