New bie question: import com.google.appengine cannot be resolved

536 views
Skip to first unread message

vijay

unread,
May 8, 2009, 6:04:32 PM5/8/09
to Google-We...@googlegroups.com, google-a...@googlegroups.com
Hi,

I am using GWT+ Appengine for building a simple web application and got stuck with a error.

I am using JDO to save some objects in datastore, I have a created a service which returns a field of persistent class which is of type  com.google.appengine.api.datastore.Key, i am calling this service from my main .java file and hence imported the required path. When running the application I got error as

Line 6: The import com.google.appengine cannot be resolved

The path com.google.appengine was auto completed and also it was not showing any error for files under .server package, the error are only for files under .client package.
I think I am missing something very basic here. Is there any restriction that I cannot import appengine packages in .client package?

Please let me know if my problem is not clear.

Regards,
Vijay

Shawn Brown

unread,
May 8, 2009, 7:40:46 PM5/8/09
to Google-We...@googlegroups.com
Have a look at http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html

I gave his solution a try and couldn't get it to work for me but
easily had a workaround and so soon gave up.

> I think I am missing something very basic here. Is there any restriction
> that I cannot import appengine packages in .client package?

Yes, the restiction is that you need access to src files so that the
client files can be transformed to javascript.

Shawn

Fred Sauer

unread,
May 9, 2009, 1:12:46 AM5/9/09
to Google-We...@googlegroups.com
Shawn,

What was it that didn't work for you?

Fred
--
Fred Sauer
fr...@allen-sauer.com

vijay

unread,
May 15, 2009, 2:17:50 AM5/15/09
to google-a...@googlegroups.com, Google-We...@googlegroups.com
Thanks Jason,
As also pointed out by Shawn that we cannot simply use Key in client code we need write a super class instead.
So now i have changed my implementation to use Long instead of key.

On Tue, May 12, 2009 at 12:03 AM, Jason (Google) <apij...@google.com> wrote:
Hi Vijay. I believe the issue here is that the GWT compiler cannot find the source code for the Key class, as detailed in the post at http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html.

You should be able to follow the steps in that post, stubbing out the Key class, to get your application working.

- Jason

Alyxandor

unread,
May 15, 2009, 6:39:39 AM5/15/09
to Google Web Toolkit
Fred's methods are rock solid, look near the middle of the page for
the super-source hack needed to make Key happy for the client side.
There are very few restrictions on what can go into the client side,
{file operations and bytecode enhancements, mainly}. To make life
easier, don't try to use any appengine stuff except annotations in
your client package; they are used by the gwt compiler, but never make
it into the actual code. ...And be careful using Long keys, I hear
that you can only retrieve data with long keys using queries, and not
the persistence or entity managers... Something about private
indexing and not being able to use them for root level getObjectById()
s or something. I can't remember, and am too tired and new to
appengine to tell you for sure. Just saying that if your
getObjectById fails, it's because it wants a String or Key key.

There's another problem I'm sure you're about to run into: Bytecode
enhancement. The dataNucleus tool uses Bytecode enhancement to make
objects that can be retrieved from the server, sent to the client,
modified there and then returned to the server and persisted back
without having to manually copy values. It's a sweet enhancement, but
like I said before, these enhancements can fail on GWT {because it
uses an Object[] with various datatypes in it, and GWT can't get
access to it because it's an "invisible" field}. The solution is to
make your entities non-detachable:

@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "false")
public class Foo{....}


Of course, this will be a pain, because now you can send the data to
gwt, but it can't put it back into the datastore. Luckily, the
Timelord, Ray Cromwell, has fixed this for us:

http://timepedia.blogspot.com/2009/04/google-appengine-and-gwt-now-marriage.html

I also posted a hack there to make his fix fully bean-compatible, in
case you're using existing code. The code I use internally is a
little different than the piece I posted there, but you get the
drift. You don't need it if you make sure that, for all of your
persistent objects, you define a getValue() setValue() pair, with
identical names. Using isValue() for booleans requires my hack.

If you want to get gwt + appengine datastore running, you have to use
Fred's super-source method on Key, in the client side, and Ray's
reflection-save method on the server-side. Also, if you want a little
more security and smaller transfers across the wire, don't forget to
mark any persistent fields that gwt won't need {like your Keys} with
@Transient. It tells RPC to skip the field, so you can keep sensitive
data where it belongs; out of the browser! {password fields, anyone?}
Reply all
Reply to author
Forward
0 new messages