我使用的是postgresql
StringBuffer sb = new StringBuffer();
sb.append("SELECT a.name as name,.....FROM 表名 a,表名 b WHERE 1 = 1 AND a.card_no = b.card_no
AND a.out_time <=[color=red] now()::TIMESTAMP[/color] AND a.out_time >= [color=red]CURRENT_DATE::TIMESTAMP[/color] AND b.card_type = 0")
this.getSession().createSQLQuery(query).lsit();
报org.hibernate.QueryException: Not all named parameters have been set: [:timestamp]
以上sql查询语句在postgresql查询无问题,但在hibernate就报错,估计是hibernate底层的原因。
使用[color=red][b]cast as[/b][/color]解决
SELECT
a.name as name,
.......
FROM
表名 a,
表名b
WHERE
1 = 1
AND a.card_no = b.card_no
AND a.out_time <= [b][color=red]cast(now() as TIMESTAMP)[/color][/b]
AND a.out_time >= [color=red]cast (CURRENT_DATE as TIMESTAMP)[/color]
AND b.card_type = 0
StringBuffer sb = new StringBuffer();
sb.append("SELECT a.name as name,.....FROM 表名 a,表名 b WHERE 1 = 1 AND a.card_no = b.card_no
AND a.out_time <=[color=red] now()::TIMESTAMP[/color] AND a.out_time >= [color=red]CURRENT_DATE::TIMESTAMP[/color] AND b.card_type = 0")
this.getSession().createSQLQuery(query).lsit();
报org.hibernate.QueryException: Not all named parameters have been set: [:timestamp]
以上sql查询语句在postgresql查询无问题,但在hibernate就报错,估计是hibernate底层的原因。
使用[color=red][b]cast as[/b][/color]解决
SELECT
a.name as name,
.......
FROM
表名 a,
表名b
WHERE
1 = 1
AND a.card_no = b.card_no
AND a.out_time <= [b][color=red]cast(now() as TIMESTAMP)[/color][/b]
AND a.out_time >= [color=red]cast (CURRENT_DATE as TIMESTAMP)[/color]
AND b.card_type = 0