[prev in list] [next in list] [prev in thread] [next in thread] 

List:       turbine-torque-dev
Subject:    Torque with hsqldb and referenced identity columns
From:       Patrick Carl <patrick.carl () web ! de>
Date:       2005-11-17 22:02:32
Message-ID: 437CFDF8.8000203 () web ! de
[Download RAW message or body]

Hello there,

when using Torque with hsqldb adn native id generation Torque uses the 
column constraint "IDENTITY" of hsqldb. This creates by default primary 
key ids starting with 0. This can lead to false behaviour in the 
following conditions:
It is possible that an object A with id 0 is created. If this object is 
refered by an related object B, the method B.getA does not work, since 
B.getA checks if B.aId != 0.

To prevent this I created the attached patches. Using them will set the 
starting id of an identity column to 1.

Please note that I wasn't abled to get the test project to work, so I 
couldn't test this patch as much as I would. Perhaps someone else can do 
this.

Patrick

["HypersonicDomainTest.java.patch" (text/plain)]

Index: src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
===================================================================
--- src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java	(Revision \
                345330)
+++ src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java	(Arbeitskopie)
 @@ -113,8 +113,8 @@
     {
         Table table = db.getTable("native");
         Column col = table.getColumn("native_id");
-        assertEquals("IDENTITY", col.getAutoIncrementString());
-        assertEquals("native_id INTEGER NOT NULL IDENTITY", col.getSqlString());
+        assertEquals("GENERATED BY DEFAULT AS IDENTITY START WITH 1", \
col.getAutoIncrementString()); +        assertEquals("native_id INTEGER NOT NULL \
GENERATED BY DEFAULT AS IDENTITY START WITH 1", col.getSqlString());  col = \
table.getColumn("name");  assertEquals("", col.getAutoIncrementString());
     }


["PlatformHypersonicImpl.java.patch" (text/plain)]

Index: src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java
===================================================================
--- src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java	(Revision 345330)
+++ src/java/org/apache/torque/engine/platform/PlatformHypersonicImpl.java	(Arbeitskopie)
@@ -47,6 +47,11 @@
         setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "BINARY"));
         setSchemaDomainMapping(new Domain(SchemaType.BLOB, "BINARY"));
         setSchemaDomainMapping(new Domain(SchemaType.CLOB, "LONGVARCHAR"));
-   }
+    }
 
+
+    public String getAutoIncrement()
+    {
+        return "GENERATED BY DEFAULT AS IDENTITY START WITH 1";
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic