0

我正在创建一个 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;
}
}
4

1 回答 1

1

看来您没有在构建路径中包含 jre 系统库。

Right click on project --> Properties --> select Java Build Path --> Libraries -->    
Add Library --> JRE System Library --> Next --> Workspace default JRE --> Finish
于 2013-05-10T07:04:41.743 回答