Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 休眠日期操作_Java_Database_Hibernate_Db2_Hql - Fatal编程技术网

Java 休眠日期操作

Java 休眠日期操作,java,database,hibernate,db2,hql,Java,Database,Hibernate,Db2,Hql,我将hibernate与DB2一起使用,出现以下问题。表/实体Customer包含字段first\u name,last\u name,birth(java.util.Date)。我需要写一个查询,将检索所有的客户在未来四天的生日。问题是,对于一些客户来说,出生年份是未知的,所以在数据库中将其设置为9999,因此我不能在where子句中进行简单的检查(因为9999年) 使用简单的hql查询 from Customer as user where month(user.birthday) = mo

我将hibernate与DB2一起使用,出现以下问题。表/实体
Customer
包含字段
first\u name
last\u name
birth
java.util.Date
)。我需要写一个查询,将检索所有的客户在未来四天的生日。问题是,对于一些客户来说,出生年份是未知的,所以在数据库中将其设置为9999,因此我不能在where子句中进行简单的检查(因为9999年)

使用简单的hql查询

from Customer as user where month(user.birthday) = month(current_date()+4 days) and day(user.birthday) = day(current_date()+4 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+3 days) and day(user.birthday) = day(current_date()+3 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+2 days) and day(user.birthday) = day(current_date()+2 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+1 day) and day(user.birthday) = day(current_date()+1 day)

9999如何转换为日期?对于未知值,通常最好使用NULL,而不是dummie。另外,您是使用HQL还是标准API查询数据库?@Vikdor:有两种情况。首先,完整日期是已知的,因此保存到db。另一种情况是只知道出生的日期和月份。例如,一个客户出生于10.12,因此它将作为10.12.9999保存到db中,我不允许更改此逻辑。@vstoyanov我想使用HQL,但也可以使用Criteria API。@Alicia87我修改了查询以符合DB2 SQL语法。我想这是我要找的,但这个月的结果会是什么(当前日期()+4)如果当前月份是12月?取决于日期如果日期是2012年12月28日,则为1。我不确定DB2 sql语法是否需要添加
+4天
+1天
。好的,我理解。因此,您添加到当前日期的数字是天数。谢谢您的帮助,您是否有关于此日期的一些参考链接有一个链接