例外:无法解析配置:hibernate.cfg.xml

其实我正在尝试做hibernate日志记录。 这是我的hibernate.cfg.xml文件

    update org.hibernate.dialect.MySQLDialect jdbc:mysql://localhost:3306/temp root root com.mysql.jdbc.Driver    

这是例外……

 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491) at org.hibernate.cfg.Configuration.configure(Configuration.java:1425) at com.subhas.mypackage.StoreData.main(StoreData.java:13) Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481) ... 2 more 

这是employee.hbm.xml

            

这是我的主要课程

 public class StoreData { public static void main(String[] args) { //creating configuration object Configuration cfg=new Configuration(); cfg.configure("hibernate.cfg.xml"); //creating session factory object SessionFactory factory=cfg.buildSessionFactory(); //creating session object Session session=factory.openSession(); //creating transaction object Transaction transaction=session.beginTransaction(); Employee employee=new Employee(); employee.setId(5000); employee.setfName("Subhas"); employee.setlName("Gupta"); //persisting the object session.persist(employee); //commit the transaction object transaction.commit(); session.close(); System.out.println("Data Saved Successfully"); } } 

我无法找到一个完美的解决方案。 有人能帮助我吗? 谢谢。

尝试将DOCTYPE更改为:

  

我不确定,但我认为你缺少一些log4J配置的BasicConfiguration.configure(),那么你就不会遇到log4J初始化exception。

我的朋友错误只是导致选择了不正确的方言。 请确保它是正确的,您还需要在映射文件中添加列属性。

         

我确定你的错误得到了解决…