Hi all!
When I try to save a row in a table the application server throws to me this exception:
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.uw.diode.entity.ParametrosInforme; nested exception is javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.uw.diode.entity.ParametrosInforme
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:488)
   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
This is the line of code:
Code:
public ParametrosInforme guardar(ParametrosInforme parametrosInforme) {
      final boolean isNew = parametrosInforme.getId() == -1;
      
      final ParametrosInforme pi = getJpaTemplate().merge(parametrosInforme);
      
      if (!isNew) {         
         getJpaTemplate().persist(pi);
        }
      
        return pi;
   }
When the application do the merge method in server I can see:
Code:
 [http-8080-1] DEBUG org.hibernate.ejb.AbstractEntityManagerImpl  - mark transaction for rollback
And when use the persist method it throws the exception.
I have two tables linking by a foreign key in many to one:
Table ReportCabecera: Code:
   create table ReportCabecera(
      Recab_idReportCabecera      number(10) not null,
      Recab_Clave                 varchar2(20),
      Recab_Descorta              varchar2(100),
      Recab_Deslarga              varchar2(500),
      Recab_Area                  varchar2(20),
      Recab_Disponibledesde       date,
      Recab_DisponibleHasta       date,
      Recab_Nomberuta             varchar2(200),
      Recab_Fegraba               date,
      Recab_Emgraba               varchar2(20)
   )tablespace TBLSPACEUWMVC;
Table ParametrosInformeCode:
   create Table ReportParametros(
      Repa_idReportParametros          number(10) not null,
      Repa_IdReportCabecera            number(10) not null,
      Repa_Clave                       varchar2(30),
      Repa_Nombre                      varchar2(100),
      Repa_Tipo                        varchar2(1),
      Repa_Valor                       varchar2(1),
      Repa_Maximo                      number(3),
      Repa_Fegraba                     date,
      Repa_Emgraba                     varchar2(20)
   )tablespace TBLSPACEUWMVC;
I can have a Many ParametrosInforme rows for each ReportCabecera row.
And here you have the Entity:
Code:
package com.uw.diode.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity
@Table(name="ReportParametros")
public class ParametrosInforme implements Serializable {
   /**
    * 
    */
   private static final long serialVersionUID = 1317245204391348960L;
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "REPORTPARAMETROS_SEQ")
   @SequenceGenerator(name="REPORTPARAMETROS_SEQ", sequenceName = "REPORTPARAMETROS_SEQ")
   @Column(name="Repa_IdReportParametros", precision=10)
   private long id;
   
   @ManyToOne
   @JoinColumn(name = "Repa_IdReportCabecera", referencedColumnName = "Recab_idReportCabecera")
   private CabeceraInforme idCabeceraInforme;
   
   @Column(name="Repa_Clave", length=30)
   private String clave;
   
   @Column(name="Repa_Nombre", length=100)
   private String nombre;
   
   @Column(name="Repa_Tipo", length=1)
   private String tipo;
   
   @Column(name="Repa_Valor", length=1)
   private String tipoValor;
   
   @Column(name="Repa_Maximo", precision=3)
   private Long longitud;
   
   @Column(name="Repa_Fegraba")
   private Date fechaGrabacion;
   
   @Column(name="Repa_Emgraba", length=20)
   private String empleadoGrabacion;
   public long getId() {
      return id;
   }
   public void setId(long id) {
      this.id = id;
   }
   public CabeceraInforme getIdCabeceraInforme() {
      return idCabeceraInforme;
   }
   public void setIdCabeceraInforme(CabeceraInforme idCabeceraInforme) {
      this.idCabeceraInforme = idCabeceraInforme;
   }
   public String getClave() {
      return clave;
   }
   public void setClave(String clave) {
      this.clave = clave;
   }
   public String getNombre() {
      return nombre;
   }
   public void setNombre(String nombre) {
      this.nombre = nombre;
   }
   public String getTipo() {
      return tipo;
   }
   public void setTipo(String tipo) {
      this.tipo = tipo;
   }
   public String getTipoValor() {
      return tipoValor;
   }
   public void setTipoValor(String tipoValor) {
      this.tipoValor = tipoValor;
   }
   public Long getLongitud() {
      return longitud;
   }
   public void setLongitud(Long longitud) {
      this.longitud = longitud;
   }
   public Date getFechaGrabacion() {
      return fechaGrabacion;
   }
   public void setFechaGrabacion(Date fechaGrabacion) {
      this.fechaGrabacion = fechaGrabacion;
   }
   public String getEmpleadoGrabacion() {
      return empleadoGrabacion;
   }
   public void setEmpleadoGrabacion(String empleadoGrabacion) {
      this.empleadoGrabacion = empleadoGrabacion;
   }
}
and the DAO:
Code:
package com.uw.diode.dao;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.exception.DataException;
import org.springframework.orm.jpa.support.JpaDaoSupport;
import com.uw.diode.entity.ParametrosInforme;
import com.uw.diode.service.ParametrosInformeService;
public class ParametrosInformeDAO extends JpaDaoSupport implements
      ParametrosInformeService {
   @SuppressWarnings("unchecked")
   @Override
   public List<ParametrosInforme> findAll(long ci) {
      List<ParametrosInforme> listaParametros = getJpaTemplate().find("select pi" +
            " from ParametrosInforme pi" +
            " where pi.idCabeceraInforme.id=?1",ci);
      
         return listaParametros;
   }
   public ParametrosInforme guardar(ParametrosInforme parametrosInforme) {
      final boolean isNew = parametrosInforme.getId() == -1;
      
      final ParametrosInforme pi = getJpaTemplate().merge(parametrosInforme);
      
      if (!isNew) {         
         getJpaTemplate().persist(pi);
        }
      
        return pi;
   }
   
   public ParametrosInforme actualizar(ParametrosInforme parametrosInforme) throws DataException,HibernateException {
      getJpaTemplate().merge(parametrosInforme);
      
      return parametrosInforme;
   }
   @SuppressWarnings("unchecked")
   @Override
   public ParametrosInforme encuentraPorId(long idInforme) {
      List<ParametrosInforme> listaParametros = getJpaTemplate().find("select pi" +
            " from ParametrosInforme pi" +
            " where pi.id=?1",idInforme);
      
      ParametrosInforme pi = new ParametrosInforme ();
      
      if (listaParametros.size() > 0)
         pi = listaParametros.get(0);
      
      return pi;
   }
}
I don't know what is happen. Could you help me, please?
Thanks!
Praedos