hibernate查询

可以用对象去查询,如

DetachedCriteria detachedCriteria = DetachedCriteria
    .forClass(Detail.class);
  detachedCriteria.add(Restrictions.eq("query", query));
  detachedCriteria.add(Restrictions.eq("type", type));
  detachedCriteria.add(Restrictions.eq("attribute", attribute));

List<Detail> list = getHibernateTemplate().findByCriteria(
    detachedCriteria);

也可以使用如下方式查询

DetachedCriteria detachedCriteria = DetachedCriteria
    .forClass(Detail.class);
  detachedCriteria.add(Restrictions.eq("query.id", query.getId()));
  detachedCriteria.add(Restrictions.eq("type.id", type.getId()));
  detachedCriteria.add(Restrictions.eq("attribute.id", attribute.getId()));

List<Detail> list = getHibernateTemplate().findByCriteria(
    detachedCriteria);

你可能感兴趣的:(Hibernate)