java - 映射中的错误 : The object of class String, 无法转换为 [class java.sql.Timestamp]

标签 java sql oracle date toplink

我启动了一条 SQL 语句,试图获取一个带有日期字段的对象,并抛出错误。我可以毫无问题地保存在数据库中,但无法恢复数据并创建对象。

错误:

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)

引发错误的查询:

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

在线文档:

@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 + "]";
    }
}

数据库:

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

我可以做什么来将该字符串解析为 Date() 并创建我的对象 DocumentoOnline? 问候。

最佳答案

表 SGSI_DOCUMENTOS 为:

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

我使用以下语句将数据类型修改为 FECHA_CAMBIO 行:

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

关于java - 映射中的错误 : The object of class String, 无法转换为 [class java.sql.Timestamp],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44500814/

相关文章:

java - org.openqa.selenium.ElementNotInteractableException : Cannot click on element

java - 在 MVC 中 servlet 和 JSP 之间存储 session 变量(错误状态 500)

SQL Server : A connection was successfully established with the server, 但随后在登录过程中发生错误

java - 加载文件到oracle数据库

sql - Oracle - 如何使用 'and' 创建不需要参数的过程

c++ - 如何使用OTL SELECT 整个表,并将其保存到文件?

java - 对 JBPM REST API 进行简单调用时出现 NotFoundException

java - 为什么 GradientPaint 在 MAC OS 上的 Java 6 和 Java 7/8 中绘制不同

python - 按列分组以在 Postgresql 中获取数组结果

mysql - 按顺序按比赛分组