-2

我有一个如下所示的标准,其中我在方法参数中传递了 id,如下所示

public List<abcObject> getabcObjects(String id) {
    Criteria query = session.createCriteria(abcObject.class);

    if(id!=null) {
        query.add(Restrictions.eq("ID", id));
    }

    List<abcObject> abcObjectsList = query.list();

    return abcObjectsList;
}

如下所示,正在从后端获取 ID 列,能否请您告诉我等效的 HQL,因为我正在寻找 wrtite HQL 以获得相同的结果

4

1 回答 1

1

HQL 语句如下:

select abc from abcObject abc where abc.id = :id

及其用途:

Integer id = 0; //this will change
String hql = "select abc from abcObject abc where abc.id = :id";
Query query = session.createQuery(hql);
query.setParameter("id", id);
List results = query.list();
于 2013-05-30T08:39:11.750 回答