Minor point: I posted Python code because you used the term "GQL". I assumed
you were working with the datastore viewer - the code sample I posted should
be valid there.

Java code in JDO uses JDOQL.

--
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 Wed, Jan 26, 2011 at 10:07 AM, Stephen Johnson <[email protected]>wrote:

> Also, check that the PMF.getPersistenceManager() returns a non-null value.
> Perhaps with the changes you've been trying you don't have the
> "transactions-optional" name in the config file matching the code.
>
>
> On Wed, Jan 26, 2011 at 11:00 AM, Stephen Johnson 
> <[email protected]>wrote:
>
>> Well, you shouldn't be getting a NullPointerException if the entity is not
>> found so something else is wrong. The correct exception would be
>> JDOObjectNotFoundException. Are you sure the PageParameters parameters is
>> not null or something else isn't null?? You don't use the 'a' variable in
>> anyway in the try/catch that would cause the NullPointerException from what
>> I see, so it has to be something else.
>>
>>
>> On Wed, Jan 26, 2011 at 12:46 AM, hrbaer <[email protected]>wrote:
>>
>>> Ok guys, even if the gql query is running I'm still not able to port
>>> this logic into my java class.
>>> Maybe someone could have a look at my code and correct/refer to my
>>> mistake(s):
>>>
>>> public GuestbookDetails( final PageParameters parameters ) throws
>>> StringValueConversionException {
>>>
>>>        PersistenceManager pm = PMF.getPersistenceManager();
>>>        try {
>>>                        Antwort a = pm.getObjectById( Antwort.class,
>>> parameters.getAsLong( Constants.ID ) );
>>>                }
>>>        catch (NullPointerException e) {
>>>                System.out.println( "No entity found." );
>>>        }
>>>
>>>        try {
>>>                        Antwort a = pm.getObjectById( Antwort.class,
>>> parameters.getLong( Constants.ID ) );
>>>                }
>>>        catch (NullPointerException e) {
>>>                System.out.println( "No entity found." );
>>>                }
>>>
>>>        try {
>>>                        Antwort a = pm.getObjectById( Antwort.class,
>>> parameters.getString( Constants.ID ) );
>>>                }
>>>        catch (NullPointerException e) {
>>>                System.out.println( "No entity found." );
>>>                }
>>>
>>>        try {
>>>                        Antwort a = pm.getObjectById( Antwort.class,
>>> parameters.getKey( Constants.ID ) );
>>>                }
>>>        catch (NullPointerException e) {
>>>                System.out.println( "No entity found." );
>>>                }
>>>
>>>        Key k = KeyFactory.createKey( Antwort.class.getSimpleName(),
>>> parameters.getLong( Constants.ID ) );
>>>        try {
>>>                        Antwort a = pm.getObjectById( Antwort.class, k );
>>>                }
>>>        catch (NullPointerException e) {
>>>                System.out.println( "No entity found." );
>>>        }
>>> }
>>>
>>> As you can imagine all querys result in the NullPointerException.
>>> Parameters.getLong always returns me the value of "ID/Name" (e.g.
>>> 1,2,3...).
>>>
>>> Apart from that I tried to fetch get my entities using the datastore
>>> object. Yet without success:
>>>
>>> DatastoreService datastore =
>>> DatastoreServiceFactory.getDatastoreService();
>>> Entity entity = null;
>>>
>>> try {
>>>     entity = datastore.get( k );
>>> }
>>> catch (EntityNotFoundException e) {
>>>    System.out.println( "No entity found." );
>>> }
>>>
>>> And last but not least with a simple query:
>>>
>>> Query q = new Query( Constants.ANTWORT );
>>> q.addFilter( Constants.ID, FilterOperator.EQUAL,
>>> parameters.getLong( Constants.ID ) );
>>> PreparedQuery pq = datastore.prepare(q);
>>> Entity entity = pq.asIterator().next();
>>> (....)
>>>
>>> I think you already know the answer...
>>>
>>> Maybe someone is able to help me out.
>>> 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
>>> [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<google-appengine-java%[email protected]>
>>> .
>>> 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
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to