For those who want to know….

 

Code in application:

 

Product dbProduct = null;

try {

Object object = pm.getObjectId(product);

            dbProduct = (Product) pm.getObjectById(new Product.ID(product.getPOSFILE_DET_GTIN()));

} catch (Throwable t) {

t.printStackTrace();

}

 

Must add inner class in jdo object

public static class ID implements java.io.Serializable {

        public String POSFILE_DET_GTIN;

 

        public ID() {

 

        }

       

        public ID(String s) {

            POSFILE_DET_GTIN = s;

        }

 

        public boolean equals(Object o) {

            if (this == o) {

                return true;

            }

 

            if (!(o instanceof Product.ID)) {

                return false;

            }

 

            final Product.ID id = (Product.ID) o;

            if (this.POSFILE_DET_GTIN != id.POSFILE_DET_GTIN) {

                return false;

            }

 

            if (this.POSFILE_DET_GTIN != id.POSFILE_DET_GTIN) {

                return false;

            }

            return true;

        }

 

Then specify inner class inside jdo metadata file:

<class

              name="Product"

              table="Product"

              requires-extent="true"

              identity-type="application"

              objectid-class="Product$ID">

 

 

And it works!!!

 

 

 

 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Leon van der Merwe
Sent: Tuesday, February 07, 2006 12:16 PM
To: [email protected]
Subject: [CTJUG Forum] JDO - getObjectById()

 

I am trying to determine if I must do an insert or update by trying to get the object from the db by using the primary key.

 

Something like this:

 

Product dbProduct = (Product)pm.getObjectById(primaryKey);

If (dbProduct != null) {

            //update

} else {

            //insert

}

 

I keep getting:  javax.jdo.JDOObjectNotFoundException: No such object

FailedObject:2050000001574

 

The object is there but its throwing its toys?

Leon van der Merwe

Programmer

Bytes Specialised Solutions

 


Tel : (+27) (21) 590-9801
Fax : (+27) (21) 590-9999

Email :
[EMAIL PROTECTED]
Web : www.btgroup.co.za
Press Office : www.itweb.co.za/office/bytes

A division of Bytes Technology Group SA (Pty) Ltd : Registration No: 2003/027603/07
A member of Bytes Technology Group Ltd; In association with KAGISO
P O Box 13287, N1 City, 7463; Akker Park, Neels Bothma Street, N1 City, 7463, Cape Town, South Africa

E-Mail Disclaimer: http://www.altron.co.za/email.asp or phone: (+27) (11) 645-3600

 

Reply via email to