Amit Sharad Amit Sharad - 14 days ago 7
Java Question

Not all named parameters have been set in specific conditions

I have using then following query in my Hibernate i.e createSQLQuery

SELECT to_char(dd, 'Mon YYYY') FROM generate_series('2013-01-01'::date, date_trunc('month', now()), '1 month') as dd


which produces output when run in PostgreSQL as


  1. "Jan 2013" "Feb 2013" . . "Feb 2014"



However while using it through createSQLQuery as below ,
it throws "org.hibernate.QueryException: Not all named parameters have been set: [:date]"

Please note that date has been used like '2013-01-01'::date

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();
}


Please suggest

Answer

Try to replace the Postgres-specific (::) type cast with a SQL-standard one - CAST ('2013-01-01' AS DATE) (or DATE '2013-01-01').