Not all named parameters have been set under certain conditions.

I have the following query in my Hibernate ie 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 on startup in PostgreSQL as

  • "January 2013" "February 2013"., "Feb 2014"

However, using it via createSQLQuery, as shown below, it throws " org.hibernate.QueryException: not all named parameters are set: [: date] "

Please note that the date was used as ' 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

+3
source share
2 answers

Postgres- (::) cast SQL- - CAST ('2013-01-01' AS DATE) ( DATE '2013-01-01').

+9

: SQL String, , . CAST, . , , , , . :

SELECT count(*), 
    array_to_string((array_agg(id order by whenCreated desc))[1\\:20], ',') ids 
FROM

org.hibernate.engine.query.spi.ParameterParser :, , , \:, . :: :, .

, , , \ Java-, escape- \\: :, .

+2

All Articles