You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-user@db.apache.org by Basil D'Souza <ba...@gmail.com> on 2010/04/12 21:14:02 UTC

getObjectById not working with a Custom PrimaryKey

Hello Guys,

I am trying to build a relatively simple application on Google App Engine. I
am trying to use JDO to build my datalayer and am running into a load of
issues. I am very new to JDO so these might be newbie issues, but I cant
seem to proceed past this.

The problem is that when i try to access an object via getObjectByID and I
create a User key to pass to the function, I was getting different errors at
different times.
1. Error while trying to convert <stringified primary key object> into
internal key
2. Object not found

The detailed steps I performed are as follows:
1. Created a New Google App Engine Project
2. Created a new Entity: User (Code attached) (fields: firstName, lastName,
emailID)
3. Created a primaryKey: UserPK (on emailID ) // I know that i could use the
default key, but i need to do this way
4. Stored it vi
User user = new User(....., "test@example.com");
pm.makePersistent(user)

5. Trying to access it by: UserPK pk = new
UserPK("com.basildsouza.odometer.datalayer.dataobjects.User$
UserPK::test@example.com <Us...@example.com>")
pm.getObjectById(pk) // This doesnt work, was initially giving my error 1
(see above) and now gives me error 2

Also when i run a query like select from ...User where emailID=
test@example.com, it does find the value properly, so i am at a loss as to
why the getObjectById isnt working.

Also, when i do pm.deletePersistant on an object i got via my above query, i
get an error saying that the primary key is null.

What i have understood from this, is that for some reason the primary key
isnt getting set for the user object. But i dont know why.

Please Help!

Code Attached:
User.java (with the UserPK as an inner static class) (Pardon the mess :)
jdoconfig.xml (generated by google)



--
Regards,
Basil Dsouza
http://www.basildsouza.com