Java “冬眠例外”;无法分析配置:hibernate.cfg.xml;运行简单的Hibernate应用程序时出错

Java “冬眠例外”;无法分析配置:hibernate.cfg.xml;运行简单的Hibernate应用程序时出错,java,hibernate,hibernate-mapping,Java,Hibernate,Hibernate Mapping,为什么会发生此hibernate异常?这很可能是因为引用了您正在使用的hibernate jar中不存在的hibernate.cfg.xml顶部的DTD 假设您没有使用Hibernate 2.0版,请检查您的Hibernate.cfg.xml中是否有: log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j s

为什么会发生此hibernate异常?

这很可能是因为引用了您正在使用的hibernate jar中不存在的
hibernate.cfg.xml
顶部的DTD

假设您没有使用Hibernate 2.0版,请检查您的Hibernate.cfg.xml中是否有:

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.javatpoint.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
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

如果您使用XML hbm文件进行实体映射,那么在上面的XML文件中:

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.javatpoint.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
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


对于一个问题来说,这是一个糟糕的标题。请将其更改为描述您的问题的内容。另外,请添加更多信息,只是stacktrace没有多大帮助。ur
hibernate.cfg.xml
是不可解析的。请在问题中添加你的hibernate.cfg.xml文件内容。请上传你的配置文件…这实际上是两个问题:log4j和hibernate。关于hibernate已经有了一个答案,但是您还应该“正确初始化log4j”。据我所知,当未找到配置文件且未完成任何编程初始化时,会出现此警告。关于如何初始化它,请参阅log4j文档。