我现在的情况是有一个合同表,需要按照合同类别统计 合同金额 而且合同类别是查询条件,可以是多个类别,怎么写 HQL,我初用hibernate不是很熟,谢谢!!!!

解决方案 »

  1.   

    public List search(String 参数L){
    Session session=new Configuration().configure().buildSessionFactory().openSession();
    Transaction tx=session.beginTransaction();
    String hql="from  实体类名  l  where l.类属性=:参数 ";//注意参数前有:
     Query query=s.createQuery(hql);
    query..setString("参数 ",参数L);
      return query.list();//返回查到的list集合
    }
    如果还不知道的话我也没办法了。呵呵!
      

  2.   

    假设合同类别是Category, 合同是Bargain. Bargain中的Category属性名为categoryList<Category> categories = new ArrayList<Category>();
    //给categories中添加数据.
    Query q = session.createQuery("FROM Bargain");
    q.setParameterList("category", categories);
    List<Bargain> bargains = q.list();
      

  3.   

    Query的setParameterList(name, list)生成的语句类似:
    bargain.category in (值列表).以下是setParameterList的官方注释:
    Bind multiple values to a named query parameter, guessing the Hibernate type from the class of the first object in the collection. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).Parameters:
    name the name of the parameter
    vals a collection of values to list