Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 例外情况:处理指令目标匹配“;[xX][mM][lL]";不允许_Java_Mysql_Hibernate - Fatal编程技术网

Java 例外情况:处理指令目标匹配“;[xX][mM][lL]";不允许

Java 例外情况:处理指令目标匹配“;[xX][mM][lL]";不允许,java,mysql,hibernate,Java,Mysql,Hibernate,当我尝试我的第一个hibernate程序时,我得到了这个错误 我的程序只需插入empID、first\u name、second\u name(表名)并使用MySQL数据库即可 尝试了很多解决方案来解决此错误 映射文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//

当我尝试我的第一个hibernate程序时,我得到了这个错误

我的程序只需插入
empID、first\u name、second\u name
(表名)并使用MySQL数据库即可

尝试了很多解决方案来解决此错误

映射文件

<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">anandhu</property>

<property   name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">update </property>
<mapping resource="employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
这是我的测试课

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;



public class EmployeeTest {

public static void main(String[] args) {
    Configuration cf = new Configuration();
    cf.configure("employee.cfg.xml");
    SessionFactory factory = cf.buildSessionFactory();
    Session session = factory.openSession();
    Employee employee = new Employee();
    employee.setID(30);
    employee.setFirstName("raju");
    employee.setLastName("ryan");
    Transaction transaction = session.beginTransaction();
    session.save(employee);
    System.out.println("updated");
    transaction.commit();
    session.close();
    factory.close();


}

}
堆栈跟踪

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: employee.cfg.xml
            at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
            at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
            at com.anandhu.hibernateproject.EmployeeTest.main(EmployeeTest.java:16)
        Caused by: org.dom4j.DocumentException: Error on line 3 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

这条线的问题是什么

<property name="firstName" column="first_name" type="string">
<property name="lastName" column="second_name" type="string">

应该是

<property name="firstName" column="first_name" type="string" />
<property name="lastName" column="second_name" type="string" />

如果显示所有stacktrace,则更简单的方法是找到一个解决方案

您可以找到使用配置和会话的示例

升级


我检查了这个映射,结果很好。看起来xml标头中的符号(可能是空格)不正确。也许这会有帮助

您想显示代码吗?请添加您的代码,cfg文件错误日志。请发布您的代码,并告诉我们您已经尝试了什么。向您的问题添加一些代码将帮助我们回答。请检查代码片段。我的表格tame是“emp”,列名是“empID”、“first_name”、“second_name”我已经添加了堆栈跟踪,请检查。@maman我已经用Hibernate 5.0.3测试了您的配置。它很好用。您使用哪个版本的Hibernate?并且,请显示所有stacktrace。你为什么只展示一部分?我不会做预测。
<property name="firstName" column="first_name" type="string">
<property name="lastName" column="second_name" type="string">
<property name="firstName" column="first_name" type="string" />
<property name="lastName" column="second_name" type="string" />