Re: [appengine-java] Can't fetch a dataset using primary key
Try: SELECT * from DB WHERE __key__ = KEY('1') You can find more documentation on this here: http://code.google.com/appengine/docs/python/datastore/gqlreference.html -- Ikai Lan Developer Programs Engineer, Google App Engine Blogger: http://googleappengine.blogspot.com Reddit: http://www.reddit.com/r/appengine Twitter: http://twitter.com/app_engine On Sun, Jan 23, 2011 at 2:00 PM, herber.m...@googlemail.com wrote: Hi all, I'm pretty new using GQL so hopefully someone can help me solving this easy (?) problem. I store my Entities in the DB using datastore.put( Entity ) without using an ID. But if I look at the Datastore Viewer I see that these entities are stored with an unique id called *ID/Name*. Now I'm trying to load such an entity using this code: SELECT * from DB WHERE ID/Name = 'id=1' - Error SELECT * from DB WHERE ID = 'id=1' - empty resultset SELECT * from DB WHERE Name = 'id=1' - empty resultset SELECT * from DB WHERE ID/Name = '1' - Error SELECT * from DB WHERE ID = '1' - empty resultset SELECT * from DB WHERE Name = '1' - empty resultset Can anybody tell me what to use to get this entry? Thanks in advance! -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.comgoogle-appengine-java%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en. -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
Re: [appengine-java] Can't fetch a dataset using primary key
Thanks for your help. Unfortunatelly this syntax isn't working at all :( I tried to run this statement within the datastore viewer but I get an error GQL Query. Apart from that the link you posted is for python, but I would need it for java. Can you/anybody help me with that too? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
Re: [appengine-java] Can't fetch a dataset using primary key
Meanwhile I tried this *java* code: PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( transactions-optional ); PersistenceManager pm = pmf.getPersistenceManager(); Antwort objectById = pm.getObjectById( Antwort.class, parameters.getLong( Constants.ID ) ); And this is my *jdocnfig.xml*: ?xml version=1.0 encoding=utf-8? jdoconfig xmlns=http://java.sun.com/xml/ns/jdo/jdoconfig; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:noNamespaceSchemaLocation=http://java.sun.com/xml/ns/jdo/jdoconfig; persistence-manager-factory name=transactions-optional property name=javax.jdo.PersistenceManagerFactoryClass value=org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory/ property name=javax.jdo.option.ConnectionURL value=appengine/ property name=javax.jdo.option.NontransactionalRead value=true/ property name=javax.jdo.option.NontransactionalWrite value=true/ property name=javax.jdo.option.RetainValues value=true/ property name=datanucleus.appengine.autoCreateDatastoreTxns value=true/ /persistence-manager-factory /jdoconfig But I get the subsequent exception: javax.jdo.JDOFatalUserException: Application code attempted to create a PersistenceManagerFactory named transactions-optional, but one with this name already exists! Instances of PersistenceManagerFactory are extremely slow to create and it is usually not necessary to create one with a given name more than once. Instead, create a singleton and share it throughout your code. If you really do need to create a duplicate PersistenceManagerFactory (such as for a unittest suite), set the appengine.orm.disable.duplicate.pmf.exception system property to avoid this error. Can anybody help me out?! -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
Re: [appengine-java] Can't fetch a dataset using primary key
Try changing Ikai's code to include the entity name like: SELECT * from DB WHERE __key__ = KEY('DB','1') if your key is a number then SELECT * from DB WHERE __key__ = KEY('DB',1) Documentation: an entity key literal, with either a string-encoded keyhttp://code.google.com/appengine/docs/python/datastore/keyclass.html#Keyor a complete path of kinds and key names/IDshttp://code.google.com/appengine/docs/python/datastore/keysandentitygroups.html: - KEY('*encoded key*') - KEY('*kind*', *'name'/ID* [, '*kind*', *'name'/ID*...]) On Mon, Jan 24, 2011 at 3:14 PM, Marc Herber herber.m...@googlemail.comwrote: Thanks for your help. Unfortunatelly this syntax isn't working at all :( I tried to run this statement within the datastore viewer but I get an error GQL Query. Apart from that the link you posted is for python, but I would need it for java. Can you/anybody help me with that too? Thanks in advance. -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.comgoogle-appengine-java%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en. -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
Re: [appengine-java] Can't fetch a dataset using primary key
Hi Marc, As the error message says, you should use a singleton to share your persistence manager. Your code must be allocating it more than once. Here ya go: import javax.jdo.JDOHelper; import javax.jdo.PersistenceManagerFactory; import javax.jdo.PersistenceManager; final public class PMF { private final static PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(transactions-optional); private PMF() {} static public PersistenceManager getPersistenceManager() { return pmf.getPersistenceManager(); } } Then to use it, just: PersistenceManager pm = PMF.getPersistenceManager(); Stephen On Mon, Jan 24, 2011 at 3:19 PM, Marc Herber herber.m...@googlemail.comwrote: Meanwhile I tried this *java* code: PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( transactions-optional ); PersistenceManager pm = pmf.getPersistenceManager(); Antwort objectById = pm.getObjectById( Antwort.class, parameters.getLong( Constants.ID ) ); And this is my *jdocnfig.xml*: ?xml version=1.0 encoding=utf-8? jdoconfig xmlns=http://java.sun.com/xml/ns/jdo/jdoconfig; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:noNamespaceSchemaLocation=http://java.sun.com/xml/ns/jdo/jdoconfig persistence-manager-factory name=transactions-optional property name=javax.jdo.PersistenceManagerFactoryClass value=org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory/ property name=javax.jdo.option.ConnectionURL value=appengine/ property name=javax.jdo.option.NontransactionalRead value=true/ property name=javax.jdo.option.NontransactionalWrite value=true/ property name=javax.jdo.option.RetainValues value=true/ property name=datanucleus.appengine.autoCreateDatastoreTxns value=true/ /persistence-manager-factory /jdoconfig But I get the subsequent exception: javax.jdo.JDOFatalUserException: Application code attempted to create a PersistenceManagerFactory named transactions-optional, but one with this name already exists! Instances of PersistenceManagerFactory are extremely slow to create and it is usually not necessary to create one with a given name more than once. Instead, create a singleton and share it throughout your code. If you really do need to create a duplicate PersistenceManagerFactory (such as for a unittest suite), set the appengine.orm.disable.duplicate.pmf.exception system property to avoid this error. Can anybody help me out?! -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.comgoogle-appengine-java%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en. -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Can't fetch a dataset using primary key
Hi all, I'm pretty new using GQL so hopefully someone can help me solving this easy (?) problem. I store my Entities in the DB using datastore.put( Entity ) without using an ID. But if I look at the Datastore Viewer I see that these entities are stored with an unique id called *ID/Name*. Now I'm trying to load such an entity using this code: SELECT * from DB WHERE ID/Name = 'id=1' - Error SELECT * from DB WHERE ID = 'id=1' - empty resultset SELECT * from DB WHERE Name = 'id=1' - empty resultset SELECT * from DB WHERE ID/Name = '1' - Error SELECT * from DB WHERE ID = '1' - empty resultset SELECT * from DB WHERE Name = '1' - empty resultset Can anybody tell me what to use to get this entry? Thanks in advance! -- You received this message because you are subscribed to the Google Groups Google App Engine for Java group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.