java - hibernate 第一个应用程序

标签 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>  

最佳答案

你能检查一下你的xml配置文件前面是否有空格吗?

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

希望这有帮助,

阿尔贝托

关于java - hibernate 第一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32977813/

相关文章:

java - 如何通过其他类访问存储到ArrayList中的对象的元素

oracle - 带有 DISTINCT 子句的 WM_CONCAT - 编译包与独立查询问题

oracle - 如何在 Oracle 10g 中获取无效对象的错误列表

oracle10g - 在插入语句中使用两个 .nextval

java - 在 xml 中存储 html 标签

java - 如何在 REST 架构中使用 Spring 和 Jackson 只请求必要的字段?

java - 设计客户端-数据库-服务器

集群环境中的数据库 ID 生成

hibernate - 任何有关 `saveAll`的文档?

java - 如何在 Java 中使用 Column.isin?