代码别写完以后总是显示:SessionFactory/Configuration cannot be resolved错误。为什么啊?是hibernate没配置正确吗?可我已经配置了Hibernate.cfg.xml文件了啊,怎么解决呢?
package org.hibernate.entity;
import org.hibernate.*;
import org hibernate.cfg.*;
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static final ThreadLocal threadLocal=new ThreadLocal();
static{
try {
Configuration cfg=new Configuration().configure();
SessionFactory=cfg.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
public static Session getSession() throws HibernateException{
Session session=(session)threadLocal.get();
if(session==null||session.isOpen()){
if(sessionFactory==null){
rebuildSessionFactory();
}
session=(sessionFactory!=null)?sessionFactory.openSession():null;
threadLocal.set(session);
}
return session;
}
public static void closeSession() throws HibernateException{
Session session=(session)threadLocal.get();
threadLocal.set(null);
if(session!=null){
session.close();
}
}
public static void rebuildSessionFactory(){
try {
configuration.configure(/hibernate.cfg.xml);
sessionFactory=cofiguration.buildSessionFactory();
} catch (Exception e) {
System.err.println("Error Creating SessionFactory!");
e.printStackTrace();
}
}
public static void shutdown(){
getSessionFactory.close();
}
}