Hibernate HQL Query : How to set a Collection as a named parameter of a Query?

后端 未结 3 1243
轮回少年
轮回少年 2020-11-30 02:13

Given the following HQL Query:

FROM
    Foo
WHERE
    Id = :id AND
    Bar IN (:barList)

I set :id using the Query object\'s <

相关标签:
3条回答
  • 2020-11-30 02:36

    In TorpedoQuery it look like this

    Entity from = from(Entity.class);
    where(from.getCode()).in("Joe", "Bob");
    Query<Entity> select = select(from);
    
    0 讨论(0)
  • 2020-11-30 02:58

    Use Query.setParameterList(), Javadoc here.

    There are four variants to pick from.

    0 讨论(0)
  • 2020-11-30 03:02

    I'm not sure about HQL, but in JPA you just call the query's setParameter with the parameter and collection.

    Query q = entityManager.createQuery("SELECT p FROM Peron p WHERE name IN (:names)");
    q.setParameter("names", names);
    

    where names is the collection of names you're searching for

    Collection<String> names = new ArrayList<String();
    names.add("Joe");
    names.add("Jane");
    names.add("Bob");
    
    0 讨论(0)
提交回复
热议问题