简体   繁体   中英

getting exception org.hibernate.exception.SQLGrammarException:

@SuppressWarnings("unchecked")
@Override
@Transactional
public List<FormFields> findFormFieldsByFormFieldIds(
        List<Integer> formFiledsIds) {
    try {
        logger.info("############### findFormFieldsByFormFieldIds dao called ################");
        System.out.println("############### getDashboardXFieldByDashboardIds size : "+formFiledsIds.size());
        Session session=sessionFactory.getCurrentSession();
        Criteria criteria=session.createCriteria(FormFields.class);
        criteria.add(Restrictions.in("fieldId", formFiledsIds)).addOrder(Order.asc("sequenceNo"));
        List<FormFields> list = criteria.list();
        logger.info("############### getDashboardXFieldByDashboardIds size : "+list.size());
        System.out.println("############### getDashboardXFieldByDashboardIds size : "+list.size());
        return list;
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return null;
}

Is there any thing wrong in above code? I got below error

org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') order by this_.sequence_no asc' at line 1

The formFiledsIds mus not be empty. I had such error when nothing was sent in the list.

Just check the list size and if it's empty return empty list as result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM