我想从一个表中获取记录,其中入场日期在一个范围内,因此'datebegin'和'endate'是Date类型,admissiondate也是Date格式。
List clients = session.createQuery("Select Id_Client from Contract contract where contract.admissiondate BETWEEN '"+ datebegin+"' and '"+endate+"'").list();
根据我的查询,我收到此错误:
org.hibernate.QueryException: could not resolve property: admissiondate of: bean.Contract [Select Id_Client from bean.Contract contract where contract.admissiondate BETWEEN 'Sat Feb 15 00:00:00 CET 2014' and 'Mon Mar 17 00:11:24 CET 2014']
它说:
Conversion failed when converting date and/or time from character
答案 0 :(得分:2)
您的查询中存在拼写错误。
应为contract.admissiondate
答案 1 :(得分:0)
尝试施放它吗?
列出clients = session.createQuery(“从合约中选择Id_Client,其中contrat.admissiondate BETWEEN'”+ cast(datebegin as datetime)+“'和'”+ cast(endate as datetime)+“'”)。list ();
答案 2 :(得分:0)
您为合约表别名,但在获取入场日期时拼写错误。试试下面的内容。
列出客户= session.createQuery(“从合约中选择Id_Client,其中contract.admissiondate BETWEEN'”+ cast(datebegin as datetime)+“'和'”+ cast(endate as datetime)+“'”)。list ();