Hibernate出错java.lang.Error: Unresolved compilation problem: 5C
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {
    public static SessionFactory sessionFactory;
     static{
         Configuration configuration=new Configuration().configure();
         sessionFactory=configuration.buildSessionFactory();
     }
    public static SessionFactory getSessionFactory() {      
        return sessionFactory;
    }

}

再调用它

SessionFactory sessionFactory=HibernateUtils.getSessionFactory();

报错
java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method getSessionFactory() from the type HibernateUtils,
是哪儿错了,求分析

1个回答

public static SessionFactory sessionFactory; 将static去掉

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问