I'm trying to query a list of data from the database witch depend on the date.
Here is my code:
@Override
public List<CoursChange> listeTauxChange(Date datJourCchn) {
Query q = sessionFactory.getCurrentSession().createQuery(
"from CoursChange c where c.datJourCchn="+datJourCchn);
return q.list();
}
The error is:
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: Apr near line 1, column 81 [from com.gtec.GestionChangeDevise.entity.CoursChange c where c.datJourCchn=Mon Apr 18 00:00:00 WAT 2016]
How is this caused and how can I solve it?
First of all never parametrize query by concatenating it with stringified parameter values. Use named or positioned parameter declaration in query string and then set parameter values to Query object.
Query q = sessionFactory.getCurrentSession().createQuery(
"from CoursChange c where c.datJourCchn=:DAT_JOUR_CCHN");
q.setParameter("DAT_JOUR_CCHN", datJourCchn, TemporalType.DATE)
return q.list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With