jpa从oracle检索日期

时间:2017-05-16 05:21:41

标签: java oracle jpa

我需要从具有DATE值的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 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列应该是DATE而不是TIMESTAMP,我拥有的日期是java.util.Date。如果需要该信息,我使用ojdbc6和oracle数据库10g

1 个答案:

答案 0 :(得分:0)

看起来我的表格列是HORA_INICIO,这似乎是问题,只是改变了它的工作。