db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Emminger <e...@ericemminger.com>
Subject Re: obtaining native primary keys problem
Date Fri, 28 Feb 2003 14:50:03 GMT
Glen

If I'm reading your code correctly, your method
public void insert(String filename)
is on Pac. Is that right?

The reason your code isn't working is that the "insert" instance of Pac 
in the insert() method is a local variable. So, when you call

test.insert("blah");
test.getPrimaryKey();

getPrimaryKey() returns 0 because it is 0.

You can fix this by changing your method signature to return an int 
value of the new primary key.

     public int insert(String filename)
     {
         Pac insert = new Pac();
         try
         {
             insert.setFilename(filename);
             insert.save();
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
         return insert.getPrimaryKey();
     }

Does that help?

Eric


Mime
View raw message