开发者

how to implement match query for Array in hibernate criteria

I have this situation

    Session session = sessionFactory.openSession();
        ArrayList<String> city;
       // in city array i have    "United States-Alabama-Anniston"
    Criteria  crit = session.createCriteria(Candidate.class);


    crit.createAlias("candidateInfo", "ci");

    crit.add(Restrictions.in("ci.city", city));
            List rsList = crit.list();
开发者_Python百科

Now this above thing work fine if i have the value "United States-Alabama-Anniston" in my database but the problem is in my database its only "Anniston"

do any one have any idea how to get the match if there's only "Anniston" in my database and i want to check it with "United States-Alabama-Anniston" which is in the ArrayList.

thanks


If I understand correctly from comment, you have values in the string that may consist of country,state and the city separated by '-'. In this case and if format with '-' is guaranteed, your best and most efficient choice would be to just walk over array and copy part after '-' to separate array that you can use in in clause.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜