GWT with JPA

637 views
Skip to first unread message

FritzTheCat

unread,
Feb 28, 2011, 8:57:32 AM2/28/11
to Google Web Toolkit
Hi people,

i try to use gwt 2.2 with JPA. For this I use the @Entity annotation
in my shared folder and i get the error message:
The import javax.persistence cannot be resolved, Entity cannot be
resolved to a type. For me it is clear that something is missing in
the .gwt.xml file and I found the rpc enhanced feature but I don't
know how to include those classes. I used the following "<define-
configuration-property name="rpc.enhancedClasses" is-multi-
valued="true"/>" in my .gwt.xml file but I also have to define my
@Entity annotated classes. So how must the be defined in the .gwt.xml
file? Any help is appreciated,

thank you and nice greetings

Juan Pablo Gardella

unread,
Feb 28, 2011, 10:18:41 AM2/28/11
to google-we...@googlegroups.com
I think you need the jpa sources in your classpath.

Juan

2011/2/28 FritzTheCat <wg27...@hotmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


FritzTheCat

unread,
Feb 28, 2011, 10:31:41 AM2/28/11
to Google Web Toolkit
Thanks Juan for your quick reply, I think I did not explain my problem
enough detailled so I try it again: My project compiles right so I
don't think it is a class-path problem in the common way: Refering to
http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes
I have to assure the following:
# The class is annotated with a JPA javax.persistence.Entity
annotation. -> I did this in my Entity object

for example:
@Entity
public class Member implements Serializable{

private static final long serialVersionUID = -8354006649751924339L;

public Long id;
}

# The fully-qualified class name is listed as one of the values of the
rpc.enhancedClasses configuration property in a .gwt.xml module file
that is part of the application. -> I think this is my problem. I
don't know how to put the class into my .gwt.xml file and I cannot
find any description how to do this, I only found some comments, that
the annotation can not be read by the client gwt code (which is clear
to me), but how can I put them into the gwt.xml file?

Thanks for your help

On 28 Feb., 16:18, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> I think you need the jpa sources in your classpath.
>
> Juan
>
> 2011/2/28 FritzTheCat <wg27_2...@hotmail.com>

Juan Pablo Gardella

unread,
Feb 28, 2011, 10:41:28 AM2/28/11
to google-we...@googlegroups.com
I don't do anything in my .gwt.xml for compiling my project. Are you compile with gwt-maven-plugin?

Here is my pom.xml and my .gwt-xml.

Juan

.gwt.xml:
<module rename-to='...'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User' />

<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

<!-- Other module inherits -->
<inherits name="com.google.gwt.activity.Activity" />
<inherits name="com.google.gwt.place.Place" />
<!-- Specify the app entry point class. -->
<entry-point class='...' />

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



</module>

pom.xml:
<?xml version="1.0" encoding="UTF-8"?>

<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId></groupId>
<artifactId></artifactId>
<packaging>war</packaging>
<version></version>


<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.1.1</gwtVersion>
<hibernate.version>3.6.1.Final</hibernate.version>
<!-- GWT needs at least java 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<!-- Persistencia -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
</exclusion>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>


<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

<plugins>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>




<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.1.0-1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<!-- goal>generateAsync</goal -->
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
documentation at codehaus.org -->
<configuration>
<runTarget>embalajemadera.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>${project.groupId}.client.Messages</i18nMessagesBundle>
<!-- Genera las interfaces Async -->
<!-- servicePattern>com/foo/client/services/*.java</servicePattern -->
</configuration>
</plugin>

<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>

<!-- IDE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>  <!-- Note 2.8 does not work with AspectJ aspect path -->
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>

<projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>


</plugins>
</build>

<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central (jboss)</id>
<name>Maven Repository Switchboard</name>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>Public Repository Group (jboss)</id>
</repository>
</repositories>

</project>


2011/2/28 FritzTheCat <wg27...@hotmail.com>

FritzTheCat

unread,
Feb 28, 2011, 10:54:34 AM2/28/11
to Google Web Toolkit
Hm, I don't use maven in my project, I saw the xml-file you posted in
some sample applications, but I don't have to use maven to solve my
@Entity annotation problem? How would you include the
javax.persistence in the class-path (you mean to include this in
the .gwt.xml file?), because at the server I already have it included,
otherwise I could not compile

Thanks for your help

On 28 Feb., 16:41, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
> 2011/2/28 FritzTheCat <wg27_2...@hotmail.com>
>
> > Thanks Juan for your quick reply, I think I did not explain my problem
> > enough detailled so I try it again: My project compiles right so I
> > don't think it is a class-path problem in the common way: Refering to
>
> >http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideServe...

Juan Pablo Gardella

unread,
Feb 28, 2011, 11:10:12 AM2/28/11
to google-we...@googlegroups.com
 but I don't have to use maven to solve my
@Entity annotation problem? 

No.

How would you include the
javax.persistence in the class-path?



 (you mean to include this in
the .gwt.xml file?)

>No.

Juan
2011/2/28 FritzTheCat <wg27...@hotmail.com>

FritzTheCat

unread,
Feb 28, 2011, 11:22:10 AM2/28/11
to Google Web Toolkit
I am using Eclipse and I have the javax.persistence in my class-path,
otherwise I could not compile? I use the @Entity for the shared object
used by client and server, the only possibility I found now is to
create a DAO object for the client, but then I have redundancy. I
think it is possible to do this without DAO but I am not sure how....,
otherwise I have to do it with it

many thanks for your help

On 28 Feb., 17:10, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
>  but I don't have to use maven to solve my
> @Entity annotation problem?
>
> No.
>
> How would you include the
> javax.persistence in the class-path?
>
> If you are using Eclipse see:http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.u...
>
> You must add source and you can download here:http://repository.jboss.org/maven2/org/hibernate/javax/persistence/hi...
>
>  (you mean to include this in
> the .gwt.xml file?)
>
> >No.
>
> Juan
> 2011/2/28 FritzTheCat <wg27_2...@hotmail.com>
> >http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0...
> ...
>
> Erfahren Sie mehr »

Juan Pablo Gardella

unread,
Feb 28, 2011, 12:34:48 PM2/28/11
to google-we...@googlegroups.com
I am using Eclipse and I have the javax.persistence in my class-path,
otherwise I could not compile?

Yes.

I use the @Entity for the shared object
used by client and server, the only possibility I found now is to
create a DAO object for the client, but then I have redundancy. I
think it is possible to do this without DAO but I am not sure how....,
otherwise I have to do it with it

Add this file to your classpath: http://tinyurl.com/4nrxk37 (JPA API SOURCES).  Then recompile the project and tell me.

Juan





2011/2/28 FritzTheCat <wg27...@hotmail.com>

--

Kayode Odeyemi

unread,
Feb 28, 2011, 12:54:27 PM2/28/11
to google-we...@googlegroups.com
You need to place your entity in server/domain folder and your DTO in
shared. After that add the client and shared folder to your
<module>.gwt.xml file.

> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?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

FritzTheCat

unread,
Feb 28, 2011, 1:04:02 PM2/28/11
to Google Web Toolkit
Thank you very much Juan, now it works without errors and the entity
is persisted!!

Is this another JPA source than the standard from Java? But it does
not matter, it works well,

many thanks

On 28 Feb., 18:34, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> I am using Eclipse and I have the javax.persistence in my class-path,
> otherwise I could not compile?
>
> Yes.
>
> I use the @Entity for the shared object
> used by client and server, the only possibility I found now is to
> create a DAO object for the client, but then I have redundancy. I
> think it is possible to do this without DAO but I am not sure how....,
> otherwise I have to do it with it
>
> Add this file to your classpath: *http://tinyurl.com/4nrxk37(JPA API
> SOURCES).  Then recompile the project and tell me.*
> *
> *
> *Juan*
> *
> *
> *
> *
> *
> *
>
> 2011/2/28 FritzTheCat <wg27_2...@hotmail.com>
> ...
>
> Erfahren Sie mehr »

Juan Pablo Gardella

unread,
Feb 28, 2011, 1:06:06 PM2/28/11
to google-we...@googlegroups.com
:) good!!

Is this another JPA source than the standard from Java?

> The specification is the same. So the API sources are equal.

Juan

2011/2/28 FritzTheCat <wg27...@hotmail.com>
Reply all
Reply to author
Forward
0 new messages