I've a method that retrieves some data from a table and return it in a java.util.List
, I need to call that method many times so I'd like to call it just once and put all the data in a java.util.Map
, how can I do this?
My method is actually like to:
private List<?> getAll(final Class objClass, final Integer parentId) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(objClass);
if (parentId != null) {
criteria.add(Restrictions.eq("tab.parent", parentId));
}
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return (List<?>) criteria.list();
}
How can I get a HashMap
like HashMap<parentId,List<?>>
?
Thanks