哪里使用hibernate.cfg.xml

2025-04-06 02:26:06
推荐回答(1个)
回答1:

你的工程是自动编译的吗?把这个类考到你的程序里然后hibernate.cfg.xml放到src下试试importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.cfg.Configuration;publicclassHibernateUtils{privatestaticSessionFactorysessionFactory;publicstaticSessionFactorygetSessionFactory(){returnsessionFactory;}publicHibernateUtils(){}static{Configurationcfg=newConfiguration();cfg.configure();sessionFactory=cfg.buildSessionFactory();}publicstaticSessiongetSession(){returnsessionFactory.openSession();}publicstaticvoidmain(String[]args){sessionFactory=HibernateUtils.getSessionFactory();System.out.println(sessionFactory);}}