I am having a lot of methods of this type:
public static List<EduUsers> getDetails(Class c, Map<String, Integer> params) {
List<EduUsers> details = null;
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Criteria cr = session.createCriteria(c);
for (Map.Entry<String, Integer> entry : params.entrySet()) {
cr.add(Restrictions.eq(entry.getKey(), entry.getValue()));
}
details = cr.list();
tx.commit();
} catch (Exception asd) {
log.debug(asd.getMessage());
if (tx != null) {
tx.commit();
}
} finally {
session.close();
}
return details;
}
I am trying to have a generic Method for them and this is what I have written so far:
public static <T> List<T> getDetails(Class<T> c, Class<T> b) {
List<T> details = null;
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Criteria cr = session.createCriteria(c);
//am stuck on iteration of the map from Class T b
details = cr.list();
tx.commit();
} catch (Exception asd) {
log.debug(asd.getMessage());
if (tx != null) {
tx.rollback();
}
} finally {
session.close();
}
return details;
}
How do I put up a generic Map onto the method?
EDIT: My Map values type can change I need to be able to put not just Integers but Strings as well and other types