Question

I have date column in TrainSeat table. I want to retrieve the data using where clause.In where claue, the date condition is specified.

Seats=(ArrayList<TrainSeat>)session.createQuery("from TrainSeat t where t.train.TrainNumber="+TrainNum+"and t.date="+date+"").list();

here 'date' is instance of Date datatype

This statements gives following errors

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: Mar near line 1, column 80 [from org.irctc.admin.TrainSeat t where t.train.TrainNumber=11007and t.date=Wed Mar 27 00:00:00 IST 2013]
Was it helpful?

Solution

Your date is converting in to String there.You can pass date as a parameter there.

Try like this

String hql = "from TrainSeat t where t.train.TrainNumber=? and t.date=?";
List result = session.createQuery(hql)
.setString(0, TrainNum)
.setParameter(1,date)
.list();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top