2014-05-09 86 views
0

我很新的hibernate.I創建簡單的應用與hibernate連接MSSQL server 2008。在執行程序時,我得到了Exception。請幫助我。提前致謝。休眠與MSSQL服務器2008

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.main.StoreData.main(StoreData.java:15) 
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 

我的conf文件。

employee.hbm.xml

<?xml version='1.0' encoding='UTF-8'?> 
    <!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping> 
    <class name="com.pojo.Employee" table="employee"> 
    <id name="id"> 
    <generator class="assigned"></generator> 
    </id> 
    <property name="firstName" column="first_name" type="string"></property> 
    <property name="lastName" column="last_name" type="string"></property>   
    </class>   
</hibernate-mapping> 

Hibernate的配置文件

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

    <hibernate-configuration>   
     <session-factory>   
      <property name="hbm2ddl.auto">update</property> 
      <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> 
      <property name="connection.url">jdbc:sqlserver://localhost;databaseName=sampleDB</property> 
      <property name="connection.username">sa</property> 
      <property name="connection.password">sa123</property> 
      <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>    
     <mapping resource="employee.hbm.xml"/> 
     </session-factory> 
    </hibernate-configuration> 
+0

你應該檢查錯字的之前,你發佈的問題 – Keerthivasan

回答

1

你必須關閉所有打開的標籤,像這樣的:

<property name="connection.password"sa123</property> 

應改爲到:

<property name="connection.password">sa123</property> 
+0

我改變了,現在我也得到了同樣的異常..請幫助我解決這個問題...謝謝n前進.. –

+0

你可以請嘗試添加「休眠「。所有屬性的前綴?我沒有看過hibernate代碼來檢查它是否是必需的,但是我有它們的前綴和它的工作原理。 –

+0

如果你會去那裏[鏈接](http://www.coderanch.com/t/523943/ORM/databases/parse-hibernate-cfg-xml),你會發現這可能與DTD加載問題有關。嘗試用本地的替代DTD。 –