有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java XML解析错误休眠

我正在尝试运行我的第一个Hibernate程序。 我想不出这个问题,因为匹配的结束标签真的在那里? 提前感谢您的帮助

Error parsing XML: /hibernate.cfg.xml(11) The element type "session-factory" must be terminated by the matching end-tag

冬眠。cfg。xml:

<?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>

        <!-- Database connection settings -->
        <property name="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
        <property name="hibernate.connection.url"/>jdbc:mysql://localhost:3306/westbahn</property>
        <property name="hibernate.connection.username" />root</property>
        <property name="hibernate.connection.password" />secretpassword</property>
        <property name="hibernate.dialect" />org.hibernate.dialect.MySQLInnoDBDialect</property>




        <property name="connection.pool_size">1</property>

        <property name="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect" </property>

        <property name="show_sql">true</property>

        <property name="current_session_context_class">thread</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

        <property name="hibernate.hbm2ddl.auto">create</property>

    </session-factory>
</hibernate-configuration>

共 (2) 个答案

  1. # 1 楼答案

    您的5个first property元素是错误的:您使用了自关闭元素,尽管它们有一个主体。例如:

    <property name="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
    

    应该是

    <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property>
                                      no slash here  ^
    
  2. # 2 楼答案

    Hibernate配置文件应该如下所示

        <hibernate-configuration>
        <session-factory>
        <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
        <property name="connection.user">xxx</property>
        <property name="connection.password">xxxx</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="show_sql">true</property>
            <property name="hibernate.hbm2ddl.auto">create</property>   
        <mapping resource="xxxx.hbm.xml"/>
         </session-factory>
    </hibernate-configuration>
    

    这可以帮到你