我是hibernate技术的新手,我正面临着标题中指定的问题。我整天都在阅读如何解决我的问题,但我没有解决它。我真的很感激能帮助我的人。以下是我的代码。
SessionUtil.java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class SessionUtil {
private static SessionUtil instance=new SessionUtil();
private SessionFactory sessionFactory;
public static SessionUtil getInstance(){
return instance;
}
//@SuppressWarnings("deprecation")
private SessionUtil(){
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
sessionFactory = configuration.buildSessionFactory();
}
public static Session getSession(){
Session session = getInstance().sessionFactory.openSession();
return session;
}
}
谢谢!