gpt4 book ai didi

java - hibernate 第一个应用程序

转载 作者:行者123 更新时间:2023-12-01 11:05:39 25 4
gpt4 key购买 nike

我在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com