public boolean save(Object obj) {
        boolean ret = false;
        Session session = sessionFactory.openSession();
        try {
            session.beginTransaction();
            int count = 0;
            if (obj instanceof Collection<?>) {
                List<?> list = (List<?>) obj;
                for (Object item : list) {
                    session.saveOrUpdate(item);
                    count++;
                    if (count == 20) { //20, same as the JDBC batch size
                        //flush a batch of inserts and release memory:
                        session.flush();
                        session.clear();
                        count = 0;
                    }
                }
            } else {
                session.saveOrUpdate(obj);
            }
            
            session.getTransaction().commit();
            ret = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
        return ret;
    }