@Test public void shouldTransformerMapWork() { Session session = em.unwrap(Session.class); List<Map> result = session.createQuery("Select c.id as id, c.name as name ,count(j) as countJob from Customer c join c.jobs j WHERE c.id = :id") .setParameter("id", 5l) .setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE) .list(); log.info("customer summary : {}",result); for (Map map : result) { Long id = (Long) map.get("id"); String name = (String) map.get("name"); long count = (long) map.get("countJob"); log.info("+++ id {} , name : {} , count : {}",id,name,count); } }
private static ResultTransformer getAlarmDefResultTransformer() { return new ResultTransformer() { private static final long serialVersionUID = -3052468375925339521L; @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { for (int i = 0, length = aliases.length; i < length; i++) { aliases[i] = aliases[i].toUpperCase(); } return AliasToEntityMapResultTransformer .INSTANCE .transformTuple(tuple, aliases); } @Override public List transformList(final List collection) { return AliasToEntityMapResultTransformer .INSTANCE .transformList(collection); } }; }
protected void executeQuery() { try { if(queryTextArea.getValue() != null && !queryTextArea.getValue().toString().trim().isEmpty()) { Query query = Db.getCurrentSession().createQuery(queryTextArea.getValue().toString()); query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); setQueryParams(query); if(!maxResultsTextField.getValue().toString().isEmpty()) { query.setMaxResults(new Integer(maxResultsTextField.getValue().toString())); } showResult(query.list()); } } catch(Exception e) { logger.debug("Error executing query", e); Notification.show(Constants.uiError, e.getMessage(), Notification.TYPE_ERROR_MESSAGE); } }
private List<Map<String, Serializable>> quickSearchMap(RequirementSearchContext query) { return makeRequirementSearchQuery(query) .setFirstResult(query.getQuickFilter().getFirst()) .setMaxResults(query.getQuickFilter().getCount()) .setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE) .list(); }