0
我啓動了一個sql語句,試圖獲取帶有Date字段的一個對象並引發錯誤。我可以在我的數據庫中保存沒有任何問題,但我無法恢復數據並創建對象。錯誤:來自映射的String類對象無法轉換爲[class java.sql.Timestamp]
錯誤:
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"),
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 + "]";
}
}
的噠tabase:
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
我能做些什麼來解析字符串日期(),並創建我的對象DocumentoOnline? 此致敬禮。
錯誤信息似乎很清楚,我,你的字符串有更多的比只是它的時間戳:'https://stackoverflow.com/questions/43551744/php-function-error-object-of-class-pdostatement09/06/17 15:05:08,022000000'。我不知道爲什麼它包含[這個問題的網址:Php函數錯誤(類的PDOStatement的對象)](https://stackoverflow.com/questions/43551744/php-function-error-object-of-class- pdostatement),我想它來自你的數據庫? –
也許你應該讓我們知道你的數據庫表(SGSI_DOCUMENTOS)是什麼樣的?列數據類型以及直接查詢Oracle數據庫時行的外觀。 –
@ OleV.V。用SGSI_DOCUMENTOS行更新。現在我看到fecha_cambio的類型是varchar2而不是時間戳... –