通过hibernate比较sql server中的时间

我试图通过SQL Server 2008中的hibernate来比较时间。

以下代码返回此错误: The data types time and datetime are incompatible in the less than or equal to operator.

 crit = session.createCriteria(ObdBlackoutHours.class); Criterion start = Restrictions.le("blackoutStart", new Date()); Criterion end = Restrictions.gt("blackoutEnd",new Date()); List list = crit.add(Restrictions.conjunction().add(start).add(end)) .list(); if(list.isEmpty()) return false; else return true; 

表格设计如下:

 CREATE TABLE [dbo].[obd_blackout_hours]( [id] [int] NOT NULL, [blackout_end] [time](7) NOT NULL, [blackout_start] [time](7) NOT NULL) 

据我所知,db只包含10:17:37而且我传递的内容是这样的,就像Thu Nov 14 10:17:37 IST 2013 ,它无法比较。 我在mysql测试了相同的代码,似乎工作得非常好。 但是SQL Server 2008正在创建这个问题。 我也尝试过

currentDate = new SimpleDateFormat("HH:mm:ss").parse(new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));

new ObdBlackoutHours(1,new Date(),new Date()).getBlackoutStart()

而不仅仅是Date()对象。 这也失败了。 我该如何比较时间并获得结果。

以下是实体类

 @Entity @Table(name = "obd_blackout_hours", schema = "dbo", catalog = "IVR_Data") public class ObdBlackoutHours implements java.io.Serializable { private int id; private Date blackoutStart; private Date blackoutEnd; private Set services = new HashSet(0); public ObdBlackoutHours() { } public ObdBlackoutHours(int id, Date blackoutStart, Date blackoutEnd) { this.id = id; this.blackoutStart = blackoutStart; this.blackoutEnd = blackoutEnd; } public ObdBlackoutHours(int id, Date blackoutStart, Date blackoutEnd, Set services) { this.id = id; this.blackoutStart = blackoutStart; this.blackoutEnd = blackoutEnd; this.services = services; } @Id @Column(name = "id", unique = true, nullable = false) public int getId() { return this.id; } public void setId(int id) { this.id = id; } @Temporal(TemporalType.TIME) @Column(name = "blackout_start", nullable = false, length = 16) public Date getBlackoutStart() { return this.blackoutStart; } public void setBlackoutStart(Date blackoutStart) { this.blackoutStart = blackoutStart; } @Temporal(TemporalType.TIME) @Column(name = "blackout_end", nullable = false, length = 16) public Date getBlackoutEnd() { return this.blackoutEnd; } public void setBlackoutEnd(Date blackoutEnd) { this.blackoutEnd = blackoutEnd; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "obdBlackoutHours") public Set getServices() { return this.services; } public void setServices(Set services) { this.services = services; } } 

请参阅以下博客:
http://blogs.msdn.com/b/jdbcteam/archive/2010/04/08/using-time-and-date-data-types-part-1-what-time-is-it.aspx
需要在hibernate连接url字符串中添加以下内容
我不确定它是真的还是假的。
sendTimeAsDateTime = FALSE