Error: The object of class String, from mapping could not be converted to [class java.sql.Timestamp]

1.8k views Asked by At

I launch a sql statement trying to get one object with a Date field and throws error. I can save without any problem in my database, but i cannot recover the data and create objects.

Error:

Exception [TOPLINK-3002] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.ConversionException
Exception Description: The object [https://stackoverflow.com/questions/43551744/php-function-error-object-of-class-pdostatement09/06/17 15:05:08,022000000], of class [class java.lang.String], from mapping [oracle.toplink.essentials.mappings.DirectToFieldMapping[fecha_cambio-->SGSI_DOCUMENTOS.FECHA_CAMBIO]] with descriptor [RelationalDescriptor(com.dominion.procop.sgsi.entidades.DocumentoOnline --> [DatabaseTable(SGSI_DOCUMENTOS)])], could not be converted to [class java.sql.Timestamp].
    at oracle.toplink.essentials.exceptions.ConversionException.incorrectTimestampFormat(ConversionException.java:99)

Query that throws error:

@NamedQuery(name="ProyContDocumentos.getDocumentosPorPC", query="SELECT p.documento FROM ProyContDocumentos p " +
        "WHERE p.idProyecto = :idProyecto AND p.idControl = :idControl ORDER BY p.idDocumento ASC"),

DocumentoOnline:

@Entity
@Table(name = "SGSI_DOCUMENTOS")
@NamedQueries({
    @NamedQuery(name="DocumentoOnline.getAll", query="SELECT d FROM DocumentoOnline d ORDER BY d.id ASC")
})

public class DocumentoOnline extends EntidadBase {

    private static final long serialVersionUID = 6891627122405312774L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_documento")
    private int                     id;

    @Column(name = "titulo", nullable = false, length = 3000)
    private String                  titulo;

    @Column(name = "descripcion", nullable = false, length = 3000)
    private String                  descripcion;

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date                fecha_cambio;

    @Column(name = "contenido", nullable = false, length = 4000)
    private String                  contenido;

    /*
     * GETTERS Y SETTERS
     */

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Date getFecha_cambio() {
        return fecha_cambio;
    }

    public void setFecha_cambio(Date fecha_cambio) {
        this.fecha_cambio = fecha_cambio;
    }

    public String getContenido() {
        return contenido;
    }

    public void setContenido(String contenido) {
        this.contenido = contenido;
    }

    @Override
    public String toString() {
        return "DocumentoOnline [id=" + id + ", titulo=" + titulo + ", descripcion=" + descripcion + ", fecha_cambio="
                + fecha_cambio + ", contenido=" + contenido + "]";
    }
}

The database:

Column Name.........Data type...length..Allow Nulls
ID_DOCUMENTO........NUMBER..............false
TITULO..............VARCHAR2....4000....false
DESCRIPCION.........VARCHAR2....4000....false
FECHA_CAMBIO........VARCHAR2....1000....false
CONTENIDO...........VARCHAR2....4000....true

What can i do to parse that String to Date() and create my object DocumentoOnline? Regards.

1

There are 1 answers

0
S. Moreno On

The table SGSI_DOCUMENTOS was:

Column Name.........Data type...length..Allow Nulls
ID_DOCUMENTO........NUMBER..............false
TITULO..............VARCHAR2....4000....false
DESCRIPCION.........VARCHAR2....4000....false
FECHA_CAMBIO........VARCHAR2....1000....false
CONTENIDO...........VARCHAR2....4000....true

I modified the data type to FECHA_CAMBIO row with the statement:

alter table SGSI_DOCUMENTOS
modify 
( 
   fecha_cambio    timestamp(6)
);