Huy,

I'm not sure I understand how your code differentiates between INSERTS
and UPDATES.  Does it assume an INSERT if the OM object primary key
already exists in the database?  Perhaps setNew(false) means an UPDATE
and setNew(true) means an INSERT?


Thanks,
tom

-----Original Message-----
From: Tom Keeney 
Sent: Wednesday, November 14, 2001 4:22 PM
To: Turbine Users List
Subject: RE: Peer.doInsert() throwing "DB Insert attempted w/o anything
specified to insert" Exception


Not sure, but maybe I should try that way.

-----Original Message-----
From: Huy Do [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 14, 2001 4:00 PM
To: Turbine Users List
Subject: RE: Peer.doInsert() throwing "DB Insert attempted w/o anything
specified to insert" Exception


When I insert things into the DB using Peer objects, I do the following:

--------
ProductDocument prodDoc = new ProductDocument();  //the OM object
 
prodDoc.setDocumentId("2000");
prodDoc.setProductId("3000");
prodDoc.setNew(true);
prodDoc.setModified(false);
prodDoc.save();
--------

Is this the standard way (most popular) ?

Thanks

Huy

> -----Original Message-----
> From: Tom Keeney [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, 15 November 2001 5:47 AM
> To: Turbine Users List
> Subject: RE: Peer.doInsert() throwing "DB Insert attempted w/o
anything
> specified to insert" Exception
> 
> 
> Well folks, I hacked at the problem and finally I had success.  The
> conclusion was rather interesting so I thought I'd share it with
> everyone.
> 
> Here's what I did:
> 
> 1) I put a System.out.println() in BasePeer.doInsert() and realized
that
> passing an OM object through the peer results in a null Criteria.  In
> other words,
> 
> ProductDocument prodDoc = new ProductDocument();  //the OM object
> 
> prodDoc.setDocumentId("2000");
> prodDoc.setProductId("3000");
> 
> ProductDocumentPeer.doInsert(prodDoc)  // <------ you get a null
> Criteria here so the insert fails
> 
> 
> 2)  Therefore, I passed a Criteria into the peer and I had success!
> 
> Criteria crit = new Criteria();
> crit.add(ProductDocumentPeer.DOCUMENT_ID, "2000");
> crit.add(ProductDocumentPeer.PRODUCT_ID, "3000");
> ProductDocumentPeer.doInsert(crit);
> 
> 
> Note that this problem occurred on a join table (ProductDocument in
this
> case) with a combined primary key (Document_ID and Product_ID).  This
> problem did not occur in a "normal" table with a single primary key.
In
> other words, I was able to do the following:
> 
> Document doc = new Document();
> 
> //set doc values....
> 
> DocumentPeer.doInsert(doc);
> 
> 
> Perhaps this is a bug?  Any ideas?
> 
> Thanks,
> Tom
> 
> 
> -----Original Message-----
> From: Tom Keeney 
> Sent: Wednesday, November 14, 2001 12:19 PM
> To: [EMAIL PROTECTED]
> Subject: Peer.doInsert() throwing "DB Insert attempted w/o anything
> specified to insert" Exception
> 
> 
> Hello all,
> 
> My Peer object is throwing the exception specified in the Subject line
> when I run the following code:
> 
>                 ProductDocument prodDoc = new ProductDocument();
> 
>                 try
>                 {
>                     prodDoc.setDocumentId("2000");
>                     prodDoc.setProductId("3000");
> 
>                     System.out.println("prodDoc: " +
> prodDoc.toString());
>                     System.out.println("documentid: " +
> prodDoc.getDocumentId().toString());
>                     System.out.println("productid: " +
> prodDoc.getProductId().toString());
> 
>                     ProductDocumentPeer.doInsert(prodDoc);
>                 }
>                 catch (Exception ex)....
> 
> 
> I'm attempting an insert against a many-to-many table named
> Novus_Product_Document that has two primary keys, DocumentId and
> ProductId.
> 
> I've traced the exception back to the doInsert() method in the
BasePeer
> class (see below). Apparently BasePeer thinks I have no table
specified.
> I am confused since I have used Peer.doInsert() successfully for a
> different table.  Is the problem because I'm trying to insert a
primary
> key value into the Novus_Product_Document table?  Any ideas are much
> appreciated.
> 
>     public static ObjectKey doInsert(Criteria criteria,
>                                      DBConnection dbCon)
>         throws Exception
>     {
>         SimpleKey id = null;
> 
>         // Get the table name and method for determining the primary
>         // key value.
>         String tableName = null;
>         Enumeration keys = criteria.keys();
>         if (keys.hasMoreElements())
>         {
>             tableName =
> criteria.getTableName((String)keys.nextElement());
>         }
>         else
>         {
>             throw new Exception("Database insert attempted without
> anything specified to insert");
>         }
> 
> 
> 
> Thanks,
> 
> Tom Keeney
> Novus Consulting Group
>  
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 
> 

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to