hibernate第一个应用程序

时间:2015-10-06 19:11:50

标签: java hibernate oracle10g

使用oracle 10g创建简单的hibernate应用程序时遇到错误

ERROR:- 
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 hibernate.StoreData.main(StoreData.java:13)
Caused by: org.dom4j.DocumentException: Error on line 1 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 2 more

映射文件: -

<?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="hibernate.Employee" table="emp1000">  
    <id name="id">  
     <generator class="assigned"></generator>  
    </id>  

    <property name="firstName"></property>  
    <property name="lastName"></property>  

  </class>  

 </hibernate-mapping>  

配置文件: -

<?xml version='1.0' encoding='UTF-8'?>  

<hibernate-configuration>  

    <session-factory>  
        <property name="hbm2ddl.auto">update</property>  
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>  
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>  
        <property name="connection.username">hr</property>  
        <property name="connection.password">hr</property>  
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>  

    <mapping resource="employee.hbm.xml"/>  
    </session-factory>  

</hibernate-configuration>  

1 个答案:

答案 0 :(得分:1)

您可以检查xml配置文件中是否有空格?

请参阅:Error: The processing instruction target matching "[xX][mM][lL]" is not allowed

希望这有帮助,

阿尔贝托