2011-08-24 3 views
2

YouTube의 Java Hibernate tutorial 사례를 따르고 있습니다. Apache Derby 서버에서 Employee 테이블을 생성해야하는 코드를 실행하려고 할 때까지 모든 것이 멋지게 보입니다. 나는 SQL 서버 (2008)를 먼저 사용하려고 시도했는데 같은 오류가 발생했습니다. 구성을 구문 분석 할 수 없습니다 : hibernate.cfg.xml 그리고 시간 초과 오류도 있습니다. 어떤 도움을 주셔서 감사합니다. 감사.Hibernate에서 "구성을 파싱하지 못했습니다"오류로 무엇을 할 수 있습니까?

다음
17:28:51,574 INFO Version:15 - Hibernate Annotations 3.4.0.GA 
17:28:51,587 INFO Environment:560 - Hibernate 3.3.2.GA 
17:28:51,590 INFO Environment:593 - hibernate.properties not found 
17:28:51,594 INFO Environment:771 - Bytecode provider name : javassist 
17:28:51,597 INFO Environment:652 - using JDK 1.4 java.sql.Timestamp handling 
17:28:51,648 INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA 
17:28:51,655 INFO Configuration:1474 - configuring from resource: hibernate.cfg.xml 
17:28:51,655 INFO Configuration:1451 - Configuration resource: hibernate.cfg.xml 
17:28:51,702 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd] 
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035) 
    at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1476) 
    at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017) 
    at com.hibernate.chapter1.TestEmployee.main(TestEmployee.java:14) 
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:1532) 
    ... 5 more 

내있는 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"> 

<hibernate-configuration> 

    <session-factory> 

     <!-- Database connection settings --> 
     <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property> 
     <property name="connection.url">jdbc:derby://localhost:1527/HibernateDb;create=true</property> 
     <property name="connection.username">user</property> 
     <property name="connection.password">password</property> 

     <!-- JDBC connection pool (use the built-in) --> 
     <property name="connection.pool_size">2</property> 

     <!-- SQL dialect --> 
     <property name="dialect">org.hibernate.dialect.DerbyDialect</property> 

     <!-- Enable Hibernate's current session context --> 
     <property name="current_session_context_class">thread</property> 

     <!-- Disable the second-level cache --> 
     <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

     <!-- Drop and re-create the database schema on startup --> 
     <property name="hbm2ddl.auto">create</property> 

    </session-factory> 

</hibernate-configuration> 

그리고, 여기에 내가 실행하고 코드가 여기에

은 내가 오류입니다 :

package com.hibernate.chapter1; 
import org.hibernate.cfg.AnnotationConfiguration; 
import org.hibernate.tool.hbm2ddl.SchemaExport; 
public class TestEmployee { 
    public static void main(String[] args) { 
     AnnotationConfiguration config = new AnnotationConfiguration(); 
     config.addAnnotatedClass(Employee.class); 
     config.configure("hibernate.cfg.xml"); 

     new SchemaExport(config).create(true, true); 
    }  
} 

내가 뭘 잘못 했니?

답변

5

이것은 hibernate.dtd를 해결할 수 없음을 의미합니다. 즉, 서버에서 해당 해상도가 시도됩니다. dtd는 jars 파일에 포함되어 있습니다. 해결 방법은 herehere을 참조하십시오.

+0

답변 해 주셔서 감사합니다. 내 hibernater3.jar 파일을 보았고 "hibernate-configuration-3.0.dtd"라는 이름의 파일이있다.이 파일은 hibernate.cfg.xml의 선언에서 정확히 어떻게 언급되었는지 알려준다. 다른 게시물을 보면 내가 사용한 경로가 다른 것으로 나타났습니다. 내 경로는 : http://www.hibernate.org/dtd/ 다른 사람들이 사용하는 동안 : http://hibernate.sourceforge.net/. 나는 길을 바꾸었고 지금은 모든 것이 효과가있다. 것은, 그것은 여전히 ​​인터넷에서 내 hibernate3.jar 대신에 당겨지고 있다고 생각합니다. 로컬 리소스에서로드되도록 강제하는 방법이 있습니까? 감사. – bobetko

+0

당신의 dtd가 인터넷에서 뽑히지 않고 있습니다. 당신이 지정한 dtd의 uri는 당신의 항아리 안에있는 dtd에있는 uri와 일치해야합니다. 그것은 모양과 웹 사이트로 열리지 만, 거기에서 뽑아되지 않습니다 .. –

관련 문제