You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Mark Lybarger <Ma...@CBC-Companies.com> on 2003/04/04 15:39:09 UTC

getting newly inserted object

I'm having troubles selecting an object after I insert it.  The
productAddList in the below code is an empty list after executing the code.
The doInsert method executes ok, and I can see the record is inserted, but
the select doesn't seem to be returning it.

        try 
        {
        	ObjectKey objectKey = ProductIdPeer.doInsert( criteria );

        	productAddList = ProductIdPeer.doSelect( criteria );

        } catch ( Exception e)
        {
        	context.put("exceptionMessage", e.getMessage());
        }

Any ideas why this isn't returning me the record?  I'd like to be able to
use the record that was just added on the next page.


Mark Lybarger
Mark.Lybarger@cbc-companies.com
CBC Companies
614.442.3741

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.467 / Virus Database: 266 - Release Date: 4/1/2003
 

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: getting newly inserted object

Posted by Eric Emminger <er...@ericemminger.com>.
Mark

> I'm having troubles selecting an object after I insert it.  The
> productAddList in the below code is an empty list after executing the code.
> The doInsert method executes ok, and I can see the record is inserted, but
> the select doesn't seem to be returning it.
> 
>         try 
>         {
>         	ObjectKey objectKey = ProductIdPeer.doInsert( criteria );

I think the criteria object may lose its properties after the above 
call, which is why the doSelect below fails.

> 
>         	productAddList = ProductIdPeer.doSelect( criteria );
> 
>         } catch ( Exception e)
>         {
>         	context.put("exceptionMessage", e.getMessage());
>         }

Try

ObjectKey objectKey = // set it to the correct value per your code
ProductIdPeer.doInsert( criteria );
productId = ProduuctIdPeer.retrieveByPK(objectKey);

Or, would it be easier to use a ProductId object, set its properties, 
save the object, and then just work with that object instead of 
selecting it from the database?

ProductId productId = new ProductId();
data.getParameters().setProperties(productId);
productId.save();
// now just use productId rather than getting it from the database

Eric


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org