JPA (EclipseLink) Entities from Tables

Boa noite a todos!

Estou trabalhando num projeto utilizando JPA. Gerei todos as minhas classes do modelo de um BD implementado.

Quando tento persistir um objeto uma exceção é lançada.

Se alguém puder dar um help aí …

[EL Severe]: 2012-10-19 23:58:25.303--ServerSession(8553126)--Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [RESPONDE.Resp1].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[participante]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Responde --> [DatabaseTable(RESPONDE)])

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [RESPONDE.Resp3].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[questao]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Responde --> [DatabaseTable(RESPONDE)])

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [RESPONDE.Resp4].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[opcaoDeResposta]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Responde --> [DatabaseTable(RESPONDE)])

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [RESPONDE.Resp2].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[questionario]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Responde --> [DatabaseTable(RESPONDE)])

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [CADASTRA.Cad1].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[aplicador]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Cadastra --> [DatabaseTable(CADASTRA)])

Exception [EclipseLink-48] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the field [CADASTRA.Cad2].  Only one may be defined as writable, all others must be specified read-only.
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[empresa]
Descriptor: RelationalDescriptor(br.ufop.shared.model.Cadastra --> [DatabaseTable(CADASTRA)])

Runtime Exceptions: 
---------------------------------------------------------

	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:471)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:615)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
	at br.ufop.server.dao.ConnectionFactory.getEntityManager(ConnectionFactory.java:27)
	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:29)
	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)
	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)
        ...
        ...

A algum tempo um amigo comentou sobre problemas com chave composta, no Hibernate. Será que tem alguma coisa haver ???
Pela exceção parece ser algum problema no relacionamento @joins

:?:

Alguém tem alguma dica aí ???

:?:

:-o Owuu!!!

Seria melhor eu fazer o mapeamento sem os relacionamentos e cria-los na mão ???

Alguém tem alguma ( :idea: ) dica aí …

flws!!!

Eu msm estou tendo que responder minhas duvidas… :lol:

http://stackoverflow.com/questions/7952115/multiple-writable-mappings-exception-in-eclipselink

Este link me ajudou mas ainda fique com duvida sobre o insertable/updatable=false

se alguém puder dar umas dicas aí … estas propriedades entram no joins ??? ou @columm ???

porque isto não foi inserido automaticamente, pois criei o mapeamento auto ???

E aí… pessoal!

Inserir as anotações, a exceção anterior parou e agora está sendo mostrada está:

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:35) 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

Se alguém puder dar um help aí … :?:

blz!!!

Alterei a versão do EclipseLink para a nova e a exceção deu uma mudada, ficou assim:

[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 18:50:02.956--ServerSession(17305627)--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 18:50:03.495--ServerSession(17305627)--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 18:50:03.498--ServerSession(17305627)--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 18:50:03.499--ServerSession(17305627)--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 18:50:03.499--ServerSession(17305627)--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 18:50:03.5--ServerSession(17305627)--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 18:50:03.5--ServerSession(17305627)--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 18:50:03.501--ServerSession(17305627)--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 18:50:03.501--ServerSession(17305627)--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 18:50:03.502--ServerSession(17305627)--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 18:50:03.502--ServerSession(17305627)--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 18:50:03.504--ServerSession(17305627)--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 18:50:03.603--ServerSession(17305627)--file:/home/milton/Área de Trabalho/workteste/jpa/war/WEB-INF/classes/_projetoJPA login successful Chamou construtor [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:35) 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: 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 Response headers Content-Type: text/plain
:?:
Se alguém já passou por um problema parecido da o toq. aí !!!

Só lembrando eu estou utilizando o GWT

Vlws!