我一直在使用,然後按照我的休眠,即createSQLQuery並非所有的命名參數已經在特定條件下被設置
SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd
查詢PostgreSQL中爲
運行時產生輸出- 「2013年1月」「 2013年2月「。 。 「2014年2月」
但是在使用它通過createSQLQuery如下, 它會拋出 「org.hibernate.QueryException:並非所有的命名參數已設置:[:日期]」
請注意該日期已被使用,如 '2013-01-01' ::日期
try{
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
Query query = session.createSQLQuery("SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd");
monthList = new ArrayList<String>();
monthList = query.list();
tx.commit();
}
請建議
嘗試替換[Postgres特定('::')類型轉換](http://www.postgresql.org/docs/current/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS )與SQL標準之一 - CAST('2013-01-01'AS DATE)'(或'DATE'2013-01-01'')。 –