On Thu, Jan 18, 2001 at 03:02:14PM +0200, Leon Messerschmidt wrote:
> Hi,
> 
> I have a hack that works.  I generated the Peer classes with the primary key
> in tact.  I then removed the "if ( !obj.isNew() )" lines ass well as the
> bodies of the setPrimaryKey methods.  Finally I remove the
> setPrimaryKeyMethod() method.
> 
> This is seems to work but it is UGLY.  I don't have any suggestions for a
> better fix at this stage :-(

How strange - I just hit this problem as well and came up with a fix.
I'm not entirely sure that it's correct so it's below, and I'd welcome
comments.

Basically I figure if a table's idMethod is set to null then neither the
if (!obj.IsNew()) in buildCriteria nor the setPrimaryKey call in the
doInsert methods are needed.


Index: Peer.vm
===================================================================
RCS file: /products/cvs/turbine/turbine/conf/torque/templates/om/Peer.vm,v
retrieving revision 1.14
diff -u -r1.14 Peer.vm
--- Peer.vm     2001/01/11 05:49:05     1.14
+++ Peer.vm     2001/01/18 22:08:18
@@ -469,7 +469,11 @@
     /** Method to do inserts */
     public static void doInsert( $table.JavaName obj ) throws Exception
     {
+        #if ($table.IdMethod == "none")
+        doInsert(buildCriteria(obj));
+        #else
         obj.setPrimaryKey(doInsert(buildCriteria(obj)));
+        #end
         obj.setNew(false);
     }
 
@@ -497,7 +501,11 @@
      */
     public static void doInsert( $table.JavaName obj, DBConnection dbCon) throws 
Exception
     {
+        #if ($table.IdMethod == "none")
+        doInsert(buildCriteria(obj), dbCon);
+        #else
         obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
+        #end
         obj.setNew(false);
     }
 
@@ -531,7 +539,7 @@
         #foreach ($col in $table.Columns)
             #set ( $cfc=$col.JavaName )
             #set ( $cup=$col.Name.toUpperCase() )
-            #if($col.isPrimaryKey())
+            #if($col.isPrimaryKey() && $col.IdMethod != "none")
         if ( !obj.isNew() )
             criteria.add( $cup, obj.get${cfc}() );
             #else
-- 
Sean Legassick
[EMAIL PROTECTED]
      Soy un hombre: nada humano me es extrano  
      
      


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to