Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.polsl.aei.SystemPraktyk.server;
- import java.util.ArrayList;
- import java.util.List;
- import pl.polsl.aei.SystemPraktyk.model.utils.HibernateUtil;
- public class HibernateHelper {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static <A,B> List<B> query(A classDB, B classDTO) {
- org.hibernate.Session s = null;
- List<B> listDBO = new ArrayList<B>();
- try {
- s = HibernateUtil.getSessionFactory()
- .openSession();
- List items = s.createCriteria(classDB.getClass()).list();
- for(Object o : items)
- {
- if(o.getClass().isAssignableFrom(classDB.getClass()))
- {
- listDBO.add((B) classDTO.getClass().getDeclaredConstructor(classDB.getClass()).newInstance(o));
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally
- {
- if(s != null)
- s.close();
- }
- return listDBO;
- }
- }
Add Comment
Please, Sign In to add comment