我正在创建一个HibernateUtil.java类来返回SessionFactory对象。但它给出错误“类型java.lang.Object无法解析。它是从所需的.class间接引用的”。我的代码是 -
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
@SuppressWarnings("deprecation")
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
答案 0 :(得分:1)
似乎你没有在构建路径中包含jre系统库。
Right click on project --> Properties --> select Java Build Path --> Libraries -->
Add Library --> JRE System Library --> Next --> Workspace default JRE --> Finish