Object instantiate(Class clazz, Serializable id) { ListableBeanFactory beanFactory = (ListableBeanFactory) getBeanFactory(); String[] beanDefinitionNames = beanFactory.getBeanNamesForType(clazz); LOG.debug(beanDefinitionNames.length + " beans registered for class: " + clazz.getName()); for (int i = 0; i < beanDefinitionNames.length; i++) { BeanWithId bean = (BeanWithId) beanFactory.getBean(beanDefinitionNames[i], BeanWithId.class);  if (clazz == bean.getClass()) { bean.setId((Integer) id); return bean; } } return null;
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) { ClassMetadata classMetadata = m_sessionFactory.getClassMetadata(entityName); Class clazz = classMetadata.getMappedClass(entityMode); return instantiate(clazz, id);
    Object instantiate(Class clazz, Serializable id) {        ListableBeanFactory beanFactory = (ListableBeanFactory) getBeanFactory();        String[] beanDefinitionNames = beanFactory.getBeanNamesForType(clazz);        LOG.debug(beanDefinitionNames.length + " beans registered for class: " + clazz.getName());        for (int i = 0; i < beanDefinitionNames.length; i++) {            BeanWithId bean = (BeanWithId) beanFactory.getBean(beanDefinitionNames[i],                    BeanWithId.class);            // only return the bean if class matches exactly (do not return subclasses            if (clazz == bean.getClass()) {                bean.setId((Integer) id);                return bean;            }        }        return null;    }    