|
Hi I am new in the list, in these days i am trying save data between two entity beans using JPA but without success, i am cheking the log nd says: Uncaught exception from servlet javax.persistence.PersistenceException: Error in meta-data for beans.distritos.id: Cannot have a java.lang.Long primary key and be a child object (owning field is beans.evento.distrito). this is my servlet: Long id = Long.parseLong(request.getParameter("idDistrito")); response.setContentType("text/html"); EntityManager cn = emf.get().createEntityManager(); Query q = cn.createQuery("SELECT d FROM distritos d WHERE d.id = :codigo"); q.setParameter("codigo",id); distritos dist = (distritos) q.getSingleResult(); EntityManager cn2 = emf.get().createEntityManager(); cn2.getTransaction().begin(); evento e = new evento(); e.setDistrito(dist); Date fecha = new Date(); e.setFechaCreacion(fecha); try{ cn2.persist(e); response.getWriter().write("ok"); }finally{ cn2.getTransaction().commit(); cn2.close(); } this is my entity bean Evento: @Entity public class evento implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; @Temporal(javax.persistence.TemporalType.DATE) private Date fechaCreacion; @JoinColumn @OneToMany(cascade = CascadeType.ALL) private distritos distrito; --getter and setter-- Distrito: @Entity public class distritos implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; private String distrito; --getter and setter-- i hope anyone help me, Thank! -- Atentamente, Johan Vallejo Elias Soluflex ERP Nextel : 827*239 Celular : 998270239 Oficina : 434-2649 anexo 102 Skype : soporte_soluflex Web : www.guiadecalles.pe Blog 1 : www.vnperu.com/blog Blog 2 : www.rfid.com.pe -- |
- [appengine-java] Problems with Spring and GAE. Mariano Cortesi
- [appengine-java] Re: Problems with Spring and GAE. Mariano Cortesi
- [appengine-java] Persistence in JPA Johan Vallejo
