1. 程式人生 > >Hibernate的HQL中in引數設定

Hibernate的HQL中in引數設定

<pre name="code" class="java">	@Override
	public String getElementByIds(String[] elementId) {
		String hql = "from ElementProperty  where ElementUUid in (:ElementUUid) order by ElementUUid ";
		List<ElementProperty> dataProperty = (List<ElementProperty>) getCurrentSession().createQuery(hql).setParameterList("ElementUUid", elementId)
				.list();
		if(dataProperty == null || dataProperty.size()==0){
		   	return "" ;
		}
		

另外一個例子

@Override
public List<String> findDeviceTokenList(List<Long> userIdList) throws Exception {
if (userIdList == null || userIdList.isEmpty()) {
return new ArrayList<String>(0);
}
String sql = "SELECT device_token FROM users u WHERE u.id IN (:userIdList)";
return session().createSQLQuery(sql).setParameterList("userIdList", userIdList).list();
}