Where is it advisable to put JPA mapped Entity classes?

68 views
Skip to first unread message

Kayode Odeyemi

unread,
Feb 20, 2011, 11:10:59 AM2/20/11
to google-a...@googlegroups.com
Hello,

I will appreciate some guide as to where exactly to put JPA mapped Entity classes. At the moment I have it
under "com.foo.server.domain". But whenever I compile the app, GWT returns:

No source code is available for type com.foo.server.domain.Users; did you forget to inherit a required 
module?

--


Kayode Odeyemi

unread,
Feb 20, 2011, 11:46:36 AM2/20/11
to google-a...@googlegroups.com
To provide more details, I am sending data to the server via GWT-RPC. On the server I'm returning an Entity class object mapped by JPA. So on the client, I requested for the object via the normal way (AsyncCallback). So when I compile the code, GWT reports a "No source code" error, meaning I'm referencing the server class on the client side.

Some of my findings report that I either create the Entity on the client side so that GWT can find it or create an implementation of the Entity on the client side overriding all the necessary methods. I am not sure about the former as I believe the Entity is meant to be on the server because it needs access to JPA. On the later, I have no idea of how to implement that as the Entity needs access to JPA (GWT can't compile server code on the client side!).

Any clues please.
--

Kayode Odeyemi

unread,
Feb 20, 2011, 1:17:04 PM2/20/11
to google-a...@googlegroups.com
I have resulted into using DTO to provide the client information about my Entity. My DTO has the same getter and setter signatures just like it's respective Entity.

But still getting "No source code is available for type com.foo.UsersDTO; did you forget to inherit a required module?"

How do I then access persisted Entity objects from the client-side?
--
Odeyemi 'Kayode O.

B.Sc(Hons) Econs, Application Developer & Systems Engineer (Sun Certified Professional),
Oracle Certified Associate, Solaris Systems Administrator, Drupal Developer

Website: http://sinati.com
Socialize with me: http://profile.to/charyorde, http://twitter.com/charyorde,
http://www.google.com/profiles/dreyemi
Skype:drecute

l.denardo

unread,
Feb 21, 2011, 3:47:32 AM2/21/11
to Google App Engine
GWT compiles your java source into javascript using a restricted
subset of allowed classes, and you cannot use anything built on non-
compatible classes, tipically you cannot read classes with persistence-
related annotatios.

Source code for your DTO must be accessible to thw GWT compiler. This
is done adding a "source" entry in your gwt.xml file, as documented
here:
http://code.google.com/webtoolkit/doc/latest/tutorial/create.html#components

In your case adding a <source path="com/foo"> should do.

regards
Lorenzo

On Feb 20, 7:17 pm, Kayode Odeyemi <drey...@gmail.com> wrote:
> I have resulted into using DTO to provide the client information about my
> Entity. My DTO has the same getter and setter signatures just like it's
> respective Entity.
>
> But still getting "No source code is available for type com.foo.UsersDTO;
> did you forget to inherit a required module?"
>
> How do I then access persisted Entity objects from the client-side?
>
>
>
> On Sun, Feb 20, 2011 at 4:46 PM, Kayode Odeyemi <drey...@gmail.com> wrote:
> > To provide more details, I am sending data to the server via GWT-RPC. On
> > the server I'm returning an Entity class object mapped by JPA. So on the
> > client, I requested for the object via the normal way (AsyncCallback). So
> > when I compile the code, GWT reports a "No source code" error, meaning I'm
> > referencing the server class on the client side.
>
> > Some of my findings report that I either create the Entity on the client
> > side so that GWT can find it or create an implementation of the Entity on
> > the client side overriding all the necessary methods. I am not sure about
> > the former as I believe the Entity is meant to be on the server because it
> > needs access to JPA. On the later, I have no idea of how to implement that
> > as the Entity needs access to JPA (GWT can't compile server code on the
> > client side!).
>
> > Any clues please.
>
> > On Sun, Feb 20, 2011 at 4:10 PM, Kayode Odeyemi <drey...@gmail.com> wrote:
>
> >> Hello,
>
> >> I will appreciate some guide as to where exactly to put JPA mapped Entity
> >> classes. At the moment I have it
> >> under "com.foo.server.domain". But whenever I compile the app, GWT
> >> returns:
>
> >> No source code is available for type com.foo.server.domain.Users; did you
> >> forget to inherit a required
> >> module?
>
> >> --
>
> > --
>
> --
> Odeyemi 'Kayode O.
>
> B.Sc(Hons) Econs, Application Developer & Systems Engineer (Sun Certified
> Professional),
> Oracle Certified Associate, Solaris Systems Administrator, Drupal Developer
>
> Website:http://sinati.com<http://www.sinati.com>
> Socialize with me:http://profile.to/charyorde,http://twitter.com/charyorde,
>
> http://www.google.com/profiles/dreyemi
> Skype:drecute

Jeff Schwartz

unread,
Feb 21, 2011, 8:07:27 AM2/21/11
to google-a...@googlegroups.com
Did you inherit the needed libs as well? For instance, I use Objectify so I import the Objectify lib as:

<inherits name="com.googlecode.objectify.Objectify"/>

You would need to do similarly for any other libs you are using.

Jeff



On Mon, Feb 21, 2011 at 7:22 AM, Kayode Odeyemi <dre...@gmail.com> wrote:
Thanks Lorenzo

Could this be a reason why my Persistence-aware Entities cannot be
compiled even after placing them under client package? I did relocate
the Entities, placed my DTOs in shared package as well as added to my
module file this:
<!-- Specify the paths for translatable code                    -->
   <source path='client'/>
   <source path='shared'/>

or does it have to be:

<source path='com/foo/client' />
<source path='com/foo/shared' />

But in as much as compile was successful, I still get the errors:

 The import javax.persistence cannot be resolved
        [ERROR] Line 10: The import javax.persistence cannot be resolved
        [ERROR] Line 18: Entity cannot be resolved to a type
        [ERROR] Line 21: Id cannot be resolved to a type
        [ERROR] Line 22: GeneratedValue cannot be resolved to a type
        [ERROR] Line 22: The attribute strategy is undefined for the
annotation type GeneratedValue
        [ERROR] Line 22: GenerationType cannot be resolved
        [ERROR] Line 25: Table cannot be resolved to a type
        [ERROR] Line 25: The attribute name is undefined for the
annotation type Table
        [ERROR] Line 26: NamedQueries cannot be resolved to a type
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> 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.
>
>


--
Odeyemi 'Kayode O.

B.Sc(Hons) Econs, Application Developer & Systems Engineer (Sun Certified
Professional),
Oracle Certified Associate, Solaris Systems Administrator, Drupal Developer

Website: http://sinati.com <http://www.sinati.com>
Socialize with me: http://profile.to/charyorde, http://twitter.com/charyorde,

http://www.google.com/profiles/dreyemi
Skype:drecute

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
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.




--
Jeff Schwartz
http://jefftschwartz.appspot.com/
follow me on twitter: @jefftschwartz

Jeff Schwartz

unread,
Feb 21, 2011, 8:05:47 AM2/21/11
to google-a...@googlegroups.com
On Mon, Feb 21, 2011 at 7:22 AM, Kayode Odeyemi <dre...@gmail.com> wrote:
   <source path='shared'/>

This is what you need

Kayode Odeyemi

unread,
Feb 21, 2011, 7:14:38 AM2/21/11
to google-a...@googlegroups.com
Thanks L

Could this be a reason why my Persistence-aware Entities cannot be
compiled even after placing them under client package? I did relocate

the Entities as well as added to my module file this:


<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>

But in as much as compile was successful, I still get the errors:

The import javax.persistence cannot be resolved
[ERROR] Line 10: The import javax.persistence cannot be resolved
[ERROR] Line 18: Entity cannot be resolved to a type
[ERROR] Line 21: Id cannot be resolved to a type
[ERROR] Line 22: GeneratedValue cannot be resolved to a type
[ERROR] Line 22: The attribute strategy is undefined for the
annotation type GeneratedValue
[ERROR] Line 22: GenerationType cannot be resolved
[ERROR] Line 25: Table cannot be resolved to a type
[ERROR] Line 25: The attribute name is undefined for the
annotation type Table
[ERROR] Line 26: NamedQueries cannot be resolved to a type


On 2/21/11, l.denardo <lorenzo...@gmail.com> wrote:

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> 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.
>
>


--
Odeyemi 'Kayode O.

B.Sc(Hons) Econs, Application Developer & Systems Engineer (Sun Certified
Professional),
Oracle Certified Associate, Solaris Systems Administrator, Drupal Developer

Socialize with me: http://profile.to/charyorde, http://twitter.com/charyorde,

http://www.google.com/profiles/dreyemi
Skype:drecute

Kayode Odeyemi

unread,
Feb 21, 2011, 8:54:09 AM2/21/11
to google-a...@googlegroups.com
Thanks once again Jeff.

I tried Objectify with a small project. Works fine. But nonetheless,
I'm still keen on getting my initial try with GWT/JPA/GAE compile and
run successfully. At the moment, I have no external library that
requires inclusion.

I see some GWT/JPA samples from the book Google Web Toolkit 2
Application Development Cookbook
(http://www.packtpub.com/article/working-entities-google-web-toolkit).
Let me see what I can get from it.

Thanks

> *Jeff Schwartz*


> http://jefftschwartz.appspot.com/
> follow me on twitter: @jefftschwartz
>

l.denardo

unread,
Feb 21, 2011, 8:46:01 AM2/21/11
to Google App Engine
Yes, that's the reason. The libraries you use must be avaiable as
source code, configured in a gwt module, and use compatible classes.

As Jeff suggested, there's a number of GWT libraries which help making
some of the non-supported classes translatable to GWT.
I can only mention this article on the subject
http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html,
but I can't give more help since I never tried such libraries myself.

Also you might want to join the GWT discussion group
http://groups.google.com/group/Google-Web-Toolkit to ask gwt related
questions.

Regards
Lorenzo

On Feb 21, 7:14 am, Kayode Odeyemi <drey...@gmail.com> wrote:
> Thanks L
>
> Could this be a reason why my Persistence-aware Entities cannot be
> compiled even after placing them under client package? I did relocate
> the Entities as well as added to my module file this:
> <!-- Specify the paths for translatable code                    -->
>     <source path='client'/>
>     <source path='shared'/>
>
> But in as much as compile was successful, I still get the errors:
>
>  The import javax.persistence cannot be resolved
>          [ERROR] Line 10: The import javax.persistence cannot be resolved
>          [ERROR] Line 18: Entity cannot be resolved to a type
>          [ERROR] Line 21: Id cannot be resolved to a type
>          [ERROR] Line 22: GeneratedValue cannot be resolved to a type
>          [ERROR] Line 22: The attribute strategy is undefined for the
> annotation type GeneratedValue
>          [ERROR] Line 22: GenerationType cannot be resolved
>          [ERROR] Line 25: Table cannot be resolved to a type
>          [ERROR] Line 25: The attribute name is undefined for the
> annotation type Table
>          [ERROR] Line 26: NamedQueries cannot be resolved to a type
>
> On 2/21/11, l.denardo <lorenzo.dena...@gmail.com> wrote:
>
>
>
> > GWT compiles your java source into javascript using a restricted
> > subset of allowed classes, and you cannot use anything built on non-
> > compatible classes, tipically you cannot read classes with persistence-
> > related annotatios.
>
> > Source code for your DTO must be accessible to thw GWT compiler. This
> > is done adding a "source" entry in your gwt.xml file, as documented
> > here:
> >http://code.google.com/webtoolkit/doc/latest/tutorial/create.html#com...
> Socialize with me:http://profile.to/charyorde,http://twitter.com/charyorde,
>
> http://www.google.com/profiles/dreyemi
> Skype:drecute

l.denardo

unread,
Feb 21, 2011, 8:51:47 AM2/21/11
to Google App Engine
Hello, that's the reason.
To use a java library in GWT this must be translatable to javascript,
i.e. source code must be available, packaged in a gwt module, and only
compatible classes must be used.

As Jeff mentioned there's a number of libraries which try to make
persistence related classes compatible to GWT. I can mention this
article on the subject http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html,
but I can't give more help since I never tried such libraries myself.

Also, you might want to join the GWT discussion group here
http://groups.google.com/group/Google-Web-Toolkit to ask gwt related
questions.

Regards
Lorenzo


On Feb 21, 7:14 am, Kayode Odeyemi <drey...@gmail.com> wrote:
> Thanks L
>
> Could this be a reason why my Persistence-aware Entities cannot be
> compiled even after placing them under client package? I did relocate
> the Entities as well as added to my module file this:
> <!-- Specify the paths for translatable code                    -->
>     <source path='client'/>
>     <source path='shared'/>
>
> But in as much as compile was successful, I still get the errors:
>
>  The import javax.persistence cannot be resolved
>          [ERROR] Line 10: The import javax.persistence cannot be resolved
>          [ERROR] Line 18: Entity cannot be resolved to a type
>          [ERROR] Line 21: Id cannot be resolved to a type
>          [ERROR] Line 22: GeneratedValue cannot be resolved to a type
>          [ERROR] Line 22: The attribute strategy is undefined for the
> annotation type GeneratedValue
>          [ERROR] Line 22: GenerationType cannot be resolved
>          [ERROR] Line 25: Table cannot be resolved to a type
>          [ERROR] Line 25: The attribute name is undefined for the
> annotation type Table
>          [ERROR] Line 26: NamedQueries cannot be resolved to a type
>
> On 2/21/11, l.denardo <lorenzo.dena...@gmail.com> wrote:
>
>
>
> > GWT compiles your java source into javascript using a restricted
> > subset of allowed classes, and you cannot use anything built on non-
> > compatible classes, tipically you cannot read classes with persistence-
> > related annotatios.
>
> > Source code for your DTO must be accessible to thw GWT compiler. This
> > is done adding a "source" entry in your gwt.xml file, as documented
> > here:
> >http://code.google.com/webtoolkit/doc/latest/tutorial/create.html#com...
> Socialize with me:http://profile.to/charyorde,http://twitter.com/charyorde,
>
> http://www.google.com/profiles/dreyemi
> Skype:drecute

Jeff Schwartz

unread,
Feb 21, 2011, 9:04:50 AM2/21/11
to google-a...@googlegroups.com
Hi Kayode,

The reason I recommend Objectify is because it eliminates the impedance mismatch that I experienced when first using JPA with App Engine. I found JPA's symantics too SQL oriented and therein lies the mismatch because Datastore is not SQL. Objectify's symantics are very close to the low level Datastore API as it is really a very thin wrapper & doesn't try to hide the fact that the Datastore isn't SQL.

I then tried the low level API and I liked it and was very productive with it but it lacked one thing that I really wanted which was the ability to use Pojos to define my schemas. Objectify not only allowed me to use Pojos but it also provides for the use of DAOs which makes organizing service level apis very easy.

Don't get me wrong, there's nothing wrong with using JPA/JDO, it just wasn't my cup of tea as they say :)

Good luck.

Jeff
Jeff Schwartz

Jeff Schwartz

unread,
Feb 21, 2011, 9:06:18 AM2/21/11
to google-a...@googlegroups.com
One more thing... Objectify's attibutes are GWT friendly so the same pojos used on the server can also be sent to the client via serialization and used there as well via the shared folder of course.

Jeff

Kayode Odeyemi

unread,
Feb 21, 2011, 10:10:15 AM2/21/11
to google-a...@googlegroups.com
You are right about Objectify Jeff. I tried it and it's slick and
simple. What I noticed about it is that it is heavily tied to JDO kind
of persistence behaviour. I'm just curios about the JPA bit. I'll dig
in more to see what I can find.

Kind regards

Kayode Odeyemi

unread,
Feb 21, 2011, 7:22:41 AM2/21/11
to google-a...@googlegroups.com
Thanks Lorenzo

> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> 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.
>
>


--
Odeyemi 'Kayode O.

B.Sc(Hons) Econs, Application Developer & Systems Engineer (Sun Certified
Professional),
Oracle Certified Associate, Solaris Systems Administrator, Drupal Developer

Socialize with me: http://profile.to/charyorde, http://twitter.com/charyorde,

http://www.google.com/profiles/dreyemi
Skype:drecute

Reply all
Reply to author
Forward
0 new messages