db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Basil D'Souza" <bas...@gmail.com>
Subject getObjectById not working with a Custom PrimaryKey
Date Mon, 12 Apr 2010 19:14:02 GMT
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 <UserPK%3A%3Atest@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

Mime
View raw message