Exception during JDO getObjectById

124 views
Skip to first unread message

Venki Balakrishnan

unread,
Jul 30, 2011, 3:53:11 AM7/30/11
to google-a...@googlegroups.com
Hello:
I have the following JDO entity class:

@PersistenceCapable(detachable = "false")
public class BizContext implements Serializable{

/**
*/
private static final long serialVersionUID = -3573604788900579800L;

@PrimaryKey
@Persistent
private String contextKey;

@Persistent
private String contextId;
....
.....

I have a logic where I am reading this entity based on the Id. The code snippet is as given below:

...

if (contextKey != null) {
result.setContext(pm.getObjectById(BizContext.class, contextKey));
}

return result;

However when I run this piece of code, I get the following exception:

at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.IllegalArgumentException: name cannot be null or empty
at com.google.appengine.api.datastore.KeyFactory.createKey(KeyFactory.java:70)
at com.google.appengine.api.datastore.KeyFactory.createKey(KeyFactory.java:57)
at org.datanucleus.store.appengine.EntityUtils.stringToInternalKey(EntityUtils.java:301)
at org.datanucleus.store.appengine.EntityUtils.idToInternalKey(EntityUtils.java:136)
at org.datanucleus.store.appengine.EntityUtils.idToInternalKey(EntityUtils.java:126)
at org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManager.getObjectById(DatastoreJDOPersistenceManager.java:63)
at com.samuuhanet.main.server.service.ContextServiceImpl.getContextDetailsLocal(ContextServiceImpl.java:135)
at com.samuuhanet.main.server.service.ContextServiceImpl.getContextDetails(ContextServiceImpl.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 34 more

Any ideas as to what could be the cause of this exception ?
Thanks a lot.

Sébastien Tromp

unread,
Jul 30, 2011, 5:22:42 AM7/30/11
to google-a...@googlegroups.com
How do you create the contextKey? Is this a value you define yourself before persisting the BizContext?

I'm no expert on this, but the documentation specifies two use cases for keys as String:

    @PrimaryKey
   
private String name;
    @PrimaryKey
   
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
   
private String encodedKey;

There is no @Persistant in the first case. Maybe this has something to do with your issue?

Cheers, 
-- 
Sébastien Tromp


2011/7/30 venkyvb <ven...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/72B1nSeM2CYJ.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Bevis

unread,
Jul 30, 2011, 7:34:23 AM7/30/11
to google-a...@googlegroups.com
Dears,

 Please try to replace your code with following code and try.

    @PrimaryKey
@Persistent
private Key contextKey;

 And persist your object to store by following way.
  
        (User is an Pojo in my application)

    Key key=KeyFactory.createKey(User.class.getSimpleName(), user.getUid());
user.setKey(key);  // you should provide a set mothod to set the Key to your filed.
pm.makePersistent(user);


Bevis.
Reply all
Reply to author
Forward
0 new messages