2015-06-23 73 views
3

我今天在公司裏創建了一個小項目。在Hibernate透視圖中,我嘗試添加新配置,以便可以從具有多列的數據庫表中輕鬆創建實體。但是,當我選擇我的項目,它給了我org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml休眠工具 - 無法添加配置 - dom4j連接Timedout -

完整的堆棧跟蹤 -

org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2158) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2137) 
    at org.jboss.tools.hibernate.proxy.ConfigurationProxy.configure(ConfigurationProxy.java:100) 
    at org.hibernate.console.ConfigurationFactory.loadConfigurationXML(ConfigurationFactory.java:355) 
    at org.hibernate.console.ConfigurationFactory.configureStandardConfiguration(ConfigurationFactory.java:279) 
    at org.hibernate.console.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:174) 
    at org.hibernate.console.ConfigurationFactory.createConfiguration(ConfigurationFactory.java:96) 
    at org.hibernate.eclipse.console.common.HibernateExtension$5.execute(HibernateExtension.java:166) 
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63) 
    at org.hibernate.eclipse.console.common.HibernateExtension.execute(HibernateExtension.java:189) 
    at org.hibernate.eclipse.console.common.HibernateExtension.buildWith(HibernateExtension.java:163) 
    at org.hibernate.eclipse.console.common.HibernateExtension.build(HibernateExtension.java:134) 
    at org.hibernate.console.ConsoleConfiguration.build(ConsoleConfiguration.java:189) 
    at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:43) 
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:98) 
    at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104) 
    at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:238) 
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) 
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect 
    at org.dom4j.io.SAXReader.read(SAXReader.java:484) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238) 
    ... 18 more 

即使使用很多Hibernate版本和改變DTD很多次後,我無法弄清楚這個問題。有人能幫助我嗎?這是一個簡單的maven項目和.cfg.xml文件被放置到src/main/java我甚至從這個URL http://www.mkyong.com/hibernate/maven-3-hibernate-3-6-oracle-11g-example-xml-mapping/下載了一個簡單的項目,然後嘗試添加新的配置,但又得到了同樣的問題。我只是更改了我擁有的各自的數據庫憑證。他們是正確的,因爲使用相同的jdbc url我成功地在Data Source Explorer中創建了一個新的數據庫連接。 請幫忙。

互聯網在我的公司工作正常。

+0

還沒有答覆:( – abhihello123

+0

你有沒有嘗試過這個線程的建議:https://forum.hibernate.org/viewtopic.php?p=2245020 –

回答

1

嘗試從改變DTD定義在hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

到:

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-configuration SYSTEM 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 

這樣的XML解析器不會嘗試加載從互聯網上DTD文件,但它會嘗試從Hibernate jar中加載它。

+0

不,它給出相同的錯誤類路徑]:無法解析配置:C :\ Workspaces \ excelws \ HibernateExample \ src \ main \ resources \ hibernate.cfg.xml 選擇core時 And [Classpath]:選擇Annotations時無法加載AnnotationConfiguration。 – abhihello123