Java jpa从oracle检索日期
您好,我需要从具有日期值的oracle数据库检索数据,我有以下实体:Java jpa从oracle检索日期,java,oracle,jpa,Java,Oracle,Jpa,您好,我需要从具有日期值的oracle数据库检索数据,我有以下实体: @Entity @Table(name="GRUPO_HORARIO_FICHA") public class grupo_horario { @Id @Column(name = "COD_GRUPO_HORARIO") private String codigo; @Temporal(TemporalType.TIME) //tried DATE,TIME and TIMESTAMP a
@Entity
@Table(name="GRUPO_HORARIO_FICHA")
public class grupo_horario {
@Id
@Column(name = "COD_GRUPO_HORARIO")
private String codigo;
@Temporal(TemporalType.TIME) //tried DATE,TIME and TIMESTAMP already
@Column(name = "HORA_INI")
private Date hora_ini; //java.util.Date
@Temporal(TemporalType.TIME) //tried DATE,TIME and TIMESTAMP already
@Column(name = "HORA_FIN")
private Date hora_fin; //java.util.Date
因此,当我在DAO中调用以下方法时,我得到null作为日期值:
grupo_horario grupo_horarios= new grupo_horario();
try {
grupo_horarios = (grupo_horario) em.createQuery("SELECT g FROM grupo_horario g WHERE g.codigo = :codigo").setParameter("codigo", codigo).getSingleResult();
} catch (NoResultException e) {return null; }
System.out.println("el resultado date=" + grupo_horarios.getCodigo()); // i get the id with no problem at all.
System.out.println("el resultado date=" + grupo_horarios.getHora_ini()); // i get null here, i need to retrieve the time.
数据库中的日期列应该是DATE而不是TIMESTAMP,我的日期是java.util.DATE。如果需要这些信息,我将使用ojdbc6和oracle database 10g看起来我的表列是HORA_INICIO,这似乎是问题所在,刚刚更改了它及其工作方式。HORA_INICIO的类型是什么,我的意思是它是java.sql.Date还是java.util.Date?如何将日期存储到数据库中?@RajuSharma hora_ini是java.util。Date@JaySmith现在是从一个已经建立的数据库,所以我直接检索数据,我将稍后存储日期。如果您一直使用oracle,请使用一种临时类型注释
TemporalType.TIMESTAMP
或TemporalType.Date
或TemporalType.Time