Remember that ordinal parameters are 1-based!

String hql = "from CoreUser cu where exists (select 1 from CoreRelation cr where cu.userId = cr.kidId and cr.parentId =?)";
return this.basicDAO.findByQuery(hql, userId);

Query query = this.basicDAO.getSessionFactory().getCurrentSession().createQuery("from CoreUser cu where exists (select 1 from CoreRelation cr where cu.userId = cr.kidId and cr.parentId =:pId)");
query.setLong("pId", userId);
return query.list();

以上两种方法这样写都没问题,出错的原因是因为写成以下这个样子:

String hql = "from CoreUser cu where exists (select 1 from CoreRelation cr where cu.userId = cr.kidId and cr.parentId =:pId)";
return this.basicDAO.findByQuery(hql, userId);

  

你可能感兴趣的:(parameter)