Estou desenvolvendo uma aplicação com GWT e JPA provider EclipseLink.
Quando executo a aplicação no Run as > Java Application como teste ela funciona normal, mas
quando executo a aplicação no Run as > Web Application a seguinte exceção é lançada:
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract boolean br.ufop.client.ServiceParticipante.cadParticipante(br.ufop.shared.model.Participante)' threw an unexpected exception: javax.persistence.PersistenceException: No Persistence provider for EntityManager named projetoJPA
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
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)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named projetoJPA
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at br.ufop.server.dao.ConnectionFactory.getEntityManager(ConnectionFactory.java:24)
at br.ufop.server.dao.JPADAOGenerico.<init>(JPADAOGenerico.java:27)
at br.ufop.server.dao.ParticipanteDaoImpl.<init>(ParticipanteDaoImpl.java:12)
at br.ufop.server.ServiceParticipanteImpl.cadParticipante(ServiceParticipanteImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 22 more
[ERROR] 500 - POST /jpa/ServiceParticipante (127.0.0.1) 57 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Referer: http://127.0.0.1:8888/Jpa.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 199
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/jpa/
Content-Type: text/x-gwt-rpc; charset=UTF-8
X-GWT-Permutation: HostedMode
Response headers
Content-Type: text/plain
A exceção diz que a fabrica não está encontrando o PersistenceUnit mas eu já conferir e está tudo declarado no Persistence.xml
Criei um método main() só pra teste no lado do servidor e tudo funciona normal quando executo como Java Application (é realizado o cadastro no BD),
mas quando executo como Web Application… da pau!
Pessoal, mudei a versão do eclipselink e a exceção lançada mudou para a seguinte:
[WARN] Server class 'javax.validation.Validation' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/opt/eclipse%20helios/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201203300216-rel-r36/gwt-2.4.0/validation-api-1.0.0.GA.jar' to the web app classpath for this session
For additional info see: file:/opt/eclipse%20helios/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201203300216-rel-r36/gwt-2.4.0/doc/helpInfo/webAppClassPath.html
[EL Info]: 2012-10-23 20:04:07.533--ServerSession(10751020)--EclipseLink, version: Eclipse Persistence Services - 2.4.0.v20120608-r11652
[WARN] Server class 'com.mysql.jdbc.Driver' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/media/DADOS/Universidade%20Federal%20de%20Ouro%20Preto/TrabalhoConclus%c3%a3oCurso/workspaceTCC/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar' to the web app classpath for this session
For additional info see: file:/opt/eclipse%20helios/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201203300216-rel-r36/gwt-2.4.0/doc/helpInfo/webAppClassPath.html
[EL Warning]: metadata: 2012-10-23 20:04:08.938--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [questionario] for the entity class [class br.ufop.shared.model.Responde] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.94--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [opcaoDeResposta] for the entity class [class br.ufop.shared.model.Responde] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.94--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [questao] for the entity class [class br.ufop.shared.model.Responde] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.941--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [participante] for the entity class [class br.ufop.shared.model.Responde] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.941--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [elemento] for the entity class [class br.ufop.shared.model.Dimensao] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.942--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [dimensao] for the entity class [class br.ufop.shared.model.Questao] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.947--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [aplicador] for the entity class [class br.ufop.shared.model.Participante] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.948--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [empresa] for the entity class [class br.ufop.shared.model.Cadastra] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.95--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [aplicador] for the entity class [class br.ufop.shared.model.Cadastra] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.951--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [tipo] for the entity class [class br.ufop.shared.model.OpcaoDeResposta] since weaving was not enabled or did not occur.
[EL Warning]: metadata: 2012-10-23 20:04:08.951--ServerSession(10751020)--Reverting the lazy setting on the OneToOne or ManyToOne attribute [questionario] for the entity class [class br.ufop.shared.model.Aplicador] since weaving was not enabled or did not occur.
[EL Info]: connection: 2012-10-23 20:04:09.07--ServerSession(10751020)--file:/home/milton/Área de Trabalho/workteste/jpa/war/WEB-INF/classes/_projetoJPA login successful
Chamou construtor
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract boolean br.ufop.client.ServiceParticipante.cadParticipante(br.ufop.shared.model.Participante)' threw an unexpected exception: java.lang.NoSuchMethodError: javax.persistence.EntityManager.getEntityManagerFactory()Ljavax/persistence/EntityManagerFactory;
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
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)
Caused by: java.lang.NoSuchMethodError: javax.persistence.EntityManager.getEntityManagerFactory()Ljavax/persistence/EntityManagerFactory;
at br.ufop.server.ServiceParticipanteImpl.cadParticipante(ServiceParticipanteImpl.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
... 22 more
[ERROR] 500 - POST /jpa/ServiceParticipante (127.0.0.1) 57 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Content-Length: 204
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/jpa/
Content-Type: text/x-gwt-rpc; charset=UTF-8
X-GWT-Permutation: HostedMode
Referer: http://127.0.0.1:8888/Jpa.html?gwt.codesvr=127.0.0.1:9997
Response headers
Content-Type: text/plain
Quando executo como uma app java se roda normal, mas quando executo como uma web app a exceção acima é lançada quando tento persistir um objeto.
a principio eu estava pensando que fosse pq eu criei algumas classes num sub pacote do servidor tipo: