数据类型的日期时间和时间在大于或等于运算符中不兼容 [英] The data types datetime and time are incompatible in the greater than or equal to operator

查看:1841
本文介绍了数据类型的日期时间和时间在大于或等于运算符中不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库表的一列中有一个变量类型的时间。
如何在Java中将此值与此字段进行比较我的意思是我可以使用date,gregoriancalendar?
我已经试过了,我仍然有这个消息,请有人给我一个建议

I have a variable type time in a column of a table of the database. How can I compare this value in java with this field I mean can i use date, gregoriancalendar? I've tried adn I still have this message, please can someone give me an advice

Date d2 = new Date();                      // timestamp now
Calendar cal = Calendar.getInstance();       // get calendar instance
cal.setTime(d2);                           // set cal to date
cal.set(Calendar.HOUR_OF_DAY, 10);            // set hour to midnight
cal.set(Calendar.MINUTE, 30);                 // set minute in hour
cal.set(Calendar.SECOND, 0);                 // set second in minute
cal.set(Calendar.MILLISECOND, 0);            // set millis in second
Date d3 = cal.getTime();   

@SuppressWarnings("unchecked")
List<Asistencia> list = (List<Asistencia>) sessionFactory
.getCurrentSession()
.createQuery(
        "select new Asistencia( asis.idAsistencia,"
        + "asis.horaInicio, asis.horaFin) "
        + "from Asistencia asis "
        + "where :hour >= asis.horaInicio and :hour <= asis.horaFin")

.setParameter("hour", d3).list();

我也用于

I also used between

where :hour between asis.horaInicio and asis.horaFin

以及消息是相同的:

ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - The data types datetime and time are incompatible in the greater than or equal to operator.

数据类型的日期时间和时间在大于或等于运算符中是不兼容的。

The data types datetime and time are incompatible in the greater than or equal to operator.

这里的类Asistencia:

Here the class Asistencia:

public class Asistencia implements java.io.Serializable {

private static final long serialVersionUID = 1L;
private long idAsistencia;
    private Date horaInicio;
    private Date horaFin;
    private int idAula;
    private int idCurso;
    private int idPeriodo;
    private Date fecha;

    public Asistencia (){
    }
    public Asistencia (long idAsistencia, Date horaInicio, Date horaFin){
          this.idAsistencia
          this.horaInicio = horaInicio;
          this.horaFin = horaFin;
    }

}

}

推荐答案

似乎唯一的问题是我使用SQL Server 2008,并且需要将sendTimeAsDateTime = false放在连接属性中。

It seems the only problem was I'm using SQL Server 2008 and is necessary to put sendTimeAsDateTime=false in the connections properties.

这里有一个类似的问题。
通过休眠比较sql server中的时间

Here a similar question. comparing time in sql server through hibernate

这篇关于数据类型的日期时间和时间在大于或等于运算符中不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆