tags:

views:

248

answers:

2

GWT with JPA

There are two projects in my eclipse workspace, let's name them:

-JPAProject -GWTProject

JPAProject contains JPA configuration stuff (persistence.xml, entity classes and so on). GWTProject is an examplary GWT project (taken from official GWT tutorial).

Both projects work fine alone. That is, I can create EMF (EntityManagerFactory) in JPAProject and get entities from the database. GWTProject works fine too, I can run it, fill the field text in the browser and get the response.

My goal is to call JPAProject from GWTProject to get entities. But the problem is that when calling DAO, I get the following exception:

[WARN] Server class 'com.emergit.service.dao.profile.ProfileDaoService' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/home/maliniak/workspace/emergit/build/classes/' to the web app classpath for this session

[WARN] /gwttest/greet
javax.persistence.PersistenceException: No Persistence provider for EntityManager named emergitPU
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at com.emergit.service.dao.profile.JpaProfileDaoService.<init>(JpaProfileDaoService.java:19)
    at pl.maliniak.server.GreetingServiceImpl.<init>(GreetingServiceImpl.java:21)  
    ...
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
[ERROR] 500 - POST /gwttest/greet (127.0.0.1) 3812 bytes

I guess that the warnings at the beginning can be omitted for now.

Do you have any ideas? I guess I am missing some basic point. All hints are highly appreciated.


Update: My persistence provider is well defined, the JPA project works well by itself.

I guess it's classpath related problem too. When running the GWT project, in WEB-INF/lib there is only gwt-servlet.jar.

Do you think that making custom Ant file to build whole thing up is the only solution (i.e. make jar out of the JPA project and copying it to WEB-INF/lib)? Or is there any Eclipse solution, so I could set the GWT project properties properly so GWT project would know to include persistence.xml file?

Update: OK, I got it working. I tried to put persitence.xml everywhere in war/WEB-INF where it was possible, but kept getting 'no persistence provider' error. It turned out that it wasn't about persistence.xml. I didn't copy the eclipselink jar to WEB-INF/lib, so it couldn't find provider class defined in persistence.xml. Copying all the jars did the thing.

Thank you very much Pascal.

A: 

Do you have a persistence provider declared in your persistence.xml? Something like this (I'm using Hibernate here, adapt it to whatever persistence provider you're using):

<persistence
  <persistence-unit name="emergitPU" transaction-type="...">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    ...
  </persistence-unit>
</persistence>

If you do, then I suspect a classpath problem. Did you package the JPA project correctly in the webapp i.e. in WEB-INF/lib?

Pascal Thivent
Thank you.I've persistence provider well defined, I mentioned that JPA project works well by itself.I guess it's classpath related problem too. When running the GWT project, in WEB-INF/lib there is only gwt-servlet.jar.Do you think that making custom ant file to build whole thing up is the only solution (i.e. make jar out of the JPA project and copying it to WEB-INF/lib)? Or is there any Eclipse solution, so I could set the GWT project properties properly so GWT project would know to include persistence.xml file?
meliniak
Ok, now it's a comment, not an answer. BTW, the bad thing is that no new line can be provided here, so the post can't be formatted for easier reading.I've made the jar with META-INF/persistence.xml in it and put it in WEB-INF/lib, but it still doesn't work.I have ran out of ideas, do you have any left to share?
meliniak
@meliniak Thank you. Just in case you didn't notice, you can edit your question to update it (I've moved the follow-up to the initial question). Back to your question now. Do you get the exact same warning when packaging the jar into `WEB-INF/lib`? If not, can you update the question with the new trace?
Pascal Thivent
+1  A: 

Struggling a lot with the same error message, I solved the problem with copying all jars (eclipselink.jar, eclipselink-jpa-modelgen_2.1.0.v20100614-r7608.jar, javax.persistence_1.0.0.jar, javax.persistence_2.0.1.v201006031150.jar) from the EclipseLink zip to the .../war/WEB-INF/lib folder of my GWT project to make everything available for the Jetty in hosted mode. As you can see from the list of files, I was using EclipseLink 2.1. Please adapt this list to your JPA implementation, if necessary.

Hoping, that this may help you as well.