Answer the question
In order to leave comments, you need to log in
How to organize such a multitype method?
public static void useLoadWithCriteria(Class<? extends AbstractHibernateClass> instance) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(instance.getClass());
criteria.add(Restrictions.eq("age", 25));
instance = (instance.getClass()) criteria.uniqueResult(); // Ошибка на строчку
}
Answer the question
In order to leave comments, you need to log in
You pass an object of type Class to the method, you don’t need to call getClass on it, I doubt that it gives you what you expect;
And inside the method, assigning values to the instance reference here does not make sense.
try the parameterized method:
public static <T extends AbstractHibernateClass> T useLoadWithCriteria(Class<T> instance) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(instance);
criteria.add(Restrictions.eq("age", 25));
return = (T) criteria.uniqueResult();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question