如何将哈希映射作为参数传递给JPA? [英] how to pass hash map as a parameter to JPA?

查看:108
本文介绍了如何将哈希映射作为参数传递给JPA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含< Sting,Value> 的hashMap参数,现在我想将这些值传递给两个JPA列。

  SELECT obj from x obj where x.no =?< String goes here>并且x.amount =?<值在这里> 

我如何使用JPQL做到这一点?

Map 来执行 select语句对于所有的键值对:

pre $ Query query = em.createQuery(SELECT obj from x obj where x.no =:x_no和x.amount =:x_amt);
列出< ResultObj> resultList = new ArrayList< ResultObj>();
Iterator< Entry< String,Value>> iter = yourMap.entrySet()。iterator();
while(iter.hasNext()){
Entry< String,Value> next = iter.next();
值的值= next.getValue();
query.setParameter(x_no,next).setParameter(x_amt,value);
ResultObj result =(ResultObj)query.getSingleResult();
resultList.add(result);
}


I have a hashMap parameter which contains <Sting,Value> now i would like to pass these values into two JPA columns.

SELECT obj from x obj where x.no=?<String goes here> and x.amount=?<value goes here >

how can i do this using JPQL ?

解决方案

With this loop you can iterate through the Map to execute select statements for all the key-value pairs:

Query query = em.createQuery("SELECT obj from x obj where x.no=:x_no and x.amount=:x_amt");
List<ResultObj> resultList = new ArrayList<ResultObj>();
Iterator<Entry<String, Value>> iter = yourMap.entrySet().iterator();
while (iter.hasNext()) {
    Entry<String, Value> next = iter.next();
    Value value = next.getValue();
    query.setParameter("x_no", next).setParameter("x_amt", value);
    ResultObj result = (ResultObj) query.getSingleResult();
    resultList.add(result);
}

这篇关于如何将哈希映射作为参数传递给JPA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆