hibernate createQuery查询传递参数的两种方式

  方式一:

复制代码
String hql = "from InventoryTask it where it.orgId=:orgId";
        Session session = getSession();
        Query query=session.createQuery(hql);
        query.setString("orgId",orgId);
        List list = query.list();
        if(list!=null&&list.size()!=0){
            return (InventoryTask)list.get(0);
        }else{
            return null;
        }
复制代码

方式二:

1
2
3
4
5
6
7
8
9
10
11
String hql = "from InventoryTask it where it.orgId=?,it.orgName" ;
         Session session = getSession();
         Query query=session.createQuery(hql);
         query.setString( "0" ,orgId);
                 query.setString( 1 ,orgName)
         List list = query.list();
         if (list!= null &&list.size()!= 0 ){
             return (InventoryTask)list.get( 0 );
         } else {
             return null ;
         }

你可能感兴趣的:(hibernate createQuery查询传递参数的两种方式)