GWT with JPA - gwt

I'm trying to build database application using GWT 1.5.3. I use JPA annotations with my objects. It seems in hosted mode GWT's RPC works fine. But when I try to compile my app using GWT-compiler I get errors like: "The import javax.persistence cannot be resolved", "Entity cannot be resolved to a type". toplink-essentials.jar is already included in my project path. What settings else do I need to solve this problem?

You can use Gilead (http://sourceforge.net/projects/gilead/) library to seamlessly manage JPA entities with GWT.
Regards

You need to include the source code for the JPA annotations in the build path for your GWT project. See here for more details:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1830&can=1&q=jpa
Specifically this jar file which will fix your problem:
http://google-web-toolkit.googlecode.com/issues/attachment?aid=1475633892125294312&name=jpa-annotations-source.jar

The general problem of the JPA and GWT is that GWT itself doesn't support fancy JPA classes, so you just do simple POJO persistent entities DTO that implements the java.io.Serializable and have simple JPA resource annotations. You need to create the entity classes in the scope of the GWT client either have it under the yourproject.client package or add them with
source path="client"
source path="folderOfYourEntities"
in the GWT project's YouProject.gwt.xml file. This will include the entity objects in the GWT client so they can used them on client side of the RPC as well. The DAO must be on the server side and can contain anything that you container supports.
The problem you have now is that when compiling, GWT compiler saids that it desn't know what those imports for JPA annonations are in the entity DTO classes. That is why you need the javax.persistence class and source codes. The jpa-annotation-source.jar reference by Rustmyself works. It is just the javax.persistence compiled class files and source codes files plus a Persistence.gwt.xml. It is a simple GWT module for the javax.persistence package. If you know how to make your own GWT module, you should have problem making all this work. By the way, the official source for the Java EE can be found on the glassfish dev site's build section wiki.glassfish.java.net
There are many other solutions that wrap your fancy PU entities to simple objects automatically using proxy or to lazy load them at run time. They work, but not optimal solutions. The best practice is to make things simple and robust from the start by having POJO JPA DTO entities on the GWT client context and full blown DAO on the server.
GWTPersistence Example
I have added an actual working example on how to make GWT and JPA work seamlessly. It is a NetBean project with source codes and deployment file. See GWTPersistence on NingZhang.info

Ok, I've found what I was missing. I needed to include jpa-annotations-source.jar in my GWT-compiler path in myapp-compile.cmd script (or in ant build file). By the way can anyone tell me the origin of this jpa-annotations-source.jar file?

I am also working with JPA <--> GWT data transformation etc.
In an effort to eliminate the DTO layer I used Gilead too.
My objection here is about translating javax.persistence. To avoid this I used XML JPA mapping declarations (orm.xml)

Simply, keep another version of your Entities but without the annotations!

Rebounding on synergetic's comment, you now (from GWT 1.5) only need to add
<source path='javax.persistence'/>
to your Module.gwt.xml

Related

ApiResourceProperty tag can not be compiled to GWT or ignored

We have a GWT app that exposes an API using Google Cloud Endpoints. As we use objectify we can not expose the Key tag to the API. For that we use the ApiResourceProperty in order to make the API ignore the field, but if we do that the GWT compilation fails.
I have tried everything, from using the exclude from source in the gwt.xml to using the #gwtincompatible
So... is there a way to ignore the ApiResourceProperty.class in the GWT compilation?
Any other idea? If not I would have to duplicate my entities for the API
Thanks in advance
The only option I had was to create custom DTOs for the API.

user spcific packages with gwt client side

I am a newbie at GWT and I have the following query.
I have a scenario where I am trying to develop a web interface(using GWT) for an existing application.
In the client side class file I would like to invoke a user specific class file, i understand that this is due to the fact that i am trying to invoke classes other than the ones http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html
I would like to know how this code can be called from the client side of the ui.
Thanks and Regards,
Bhavya
If you have a source code for the class you want to use and it is using only the supported Java classes, you can simply add your specific classes to client packages. If this is a reusable code, you can create a new GWT module and inherit it in your application. You can also simply move those classes to your client packages OR add a new client folder in you .gwt.xml file (add one more <source> tag)
If your class is not compilable by GWT, then I think you need to use it through RPC service.
If the code is translatable into JavaScript, you could for example put your individual class files into a jar and add it to the Build Path - as you would do in a 'regular' Java Project.

JPA Entities for GWT

I have developed one GWT project . I have created one JPA entity called Employee. I want that entity to be persisted to the database. My Employee is
located under com.mygwt.client.bean. Now my question is that are all the entities meant to be located at server side? When I tried to create under
the server side I got the exception saying Forgot to inherit the module for the Employee. Is there any other way for creating the entities in server side instead of creating the entity in client side? Please suggest the way I am doing right or not.
Put in the server side and then add an additional <source path='..'/> to your .gwt.xml to tell GWT where the sources are.
The above answer is right. But you have to be careful what you put in the packages you add using <source path='..' />. The tag <source path='...' /> in your project gwt.xml file tells the GWT compiler where to look for client side-code to convert to JavaScript. So you can only put classes in there that can be converted to JavaScript. You can not just add the server-side package which contains your remote servlets, that is wrong and won't work.
I suggest the following structure:
com.mycompany.client
com.mycompany.shared
com.mycompany.server
Basically client code is in the client directory, and in shared you keep classes (transfer objects, models, validators...) which are used client-side and server-side. Then put these lines into the project gwt.xml file:
<source path='com.mycompany.client' />
<source path='com.mycompany.shared' />
You'll have to be careful to access the server library jars only from the com.mycompany.server tree.
Also, not try to send an object from the server libraries over the wire to the client. If you need to send server library objects over the wire you'll have to have the source to the library -- it's a mess. It is easier to create a DTO class in com.mycompany.shared that is created my the sevrlet of your application from the server side information.
Stuart

Wicket 1.4 EJB Support

I tried implementing the JavaEE Inject jar from Wicket Stuff. (glassfish v3, wicket 1.4)
- however, the code given in the tutorial doesn't work
method
addComponentInstantiationListener in
class org.apache.wicket.Application
cannot be applied to given types
required:
org.apache.wicket.application.IComponentInstantiationListener
found:
org.wicketstuff.javaee.injection.JavaEEComponentInjector
looks to me like the API has changed. The JIRA link inside
http://wicketstuff.org/confluence/display/STUFFWIKI/JavaEE+Inject
and the Repository link are both broken. Is it still maintained?
Another short question: Is it possible to populate ListView directly with entity beans? I'd like to avoid too many proxy classes.
Thanks in advance
Yes, you can inject a ListView with entity beans. You should do so by creating an implementation of IDataProvider (or one of it's sub-interfaces) for the iterator and have it wrap the entities with LoadableDetachableModel so they can be reloaded instead of serialized as a part of the session.
Figured it out: I didn't expect there to be a difference between 1.4.13 and 1.4.14 but apparently the API changed there significantly.

Spring roo with GWT : How to stop scaffolding generation?

I am trying Spring roo with GWT. To generate the basic structure I used gwt:setup which generated the initial scaffolding but after that I want to stop the scaffolding, particularly when I annotate my domain class with #RooEntity.
thanks in advance
The solution i found is to rename the generated directory from gwt to something else. Than roo stops generating the scaffolding code when class is marked with RooEntity
I think you can remove the #RooGwtMirroredFrom from the *Record files