@Override public T toValue(String id) { Session session = sessionFactory.getCurrentSession(); boolean close = session == null; if (session == null) { session = sessionFactory.openSession(); } try { return session.getById(id, cl); } finally { if (close) { session.close(); } } } };