找不到Hibernate.cgf.xml

时间:2015-09-09 06:52:53

标签: hibernate

我正在尝试运行hibrnate代码,但我会将错误消息的日期

public class emp
     {
        public static void main(String[] args) 
    {
            //creating configuration object 
            Configuration cfg=new Configuration(); 

        cfg.configure("hibernate.cfg.xml");
//populates the data of the 

       //creating seession factory object 

        SessionFactory factory=cfg.buildSessionFactory();
        //creating session object

        Session session=factory.openSession(); 

       //creating transaction object

        Transaction t=session.beginTransaction();

        Employee e1=new Employee();

         e1.setId(115);

          e1.setFname("rahul");
          e1.setLastName("jaiswal"); 
          session.persist(e1);
//persisting the object 

t.commit();

//transaction is commited

        session.close();

         System.out.println("successfully saved"); 
    }

}

1 个答案:

答案 0 :(得分:1)

hibernate.cfg.xml文件应该位于项目类路径的根目录中。如果您使用Maven,请确保它应该像

src > resources > hibernate.cfg.xml.

否则:

提供hibernate.cfg.xml的完整路径名