Hibernate 无效映射异常

发布于 2025-01-07 19:58:23 字数 5729 浏览 1 评论 0原文

我正在使用最新的休眠罐。 (即 hibernate-release-4.0.1.Final ) 在以前的版本中,我得到了正确的输出。 我更换了休眠罐,但有一个例外。

org.hibernate.InvalidMappingException:无法读取 XML

我阅读了一些博客并将文档类型更改为 但

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

错误仍然存​​在。

我正在附加我的 cfg.xml 和我的 hbm.xml 之一(因为所有 10 个都无法附加)

请让我告诉我问题是什么以及应该采取什么解决方案。 谢谢

错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.cluster.action.Action.main(Action.java:19)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)
    at org.hibernate.cfg.Configuration.add(Configuration.java:474)
    at org.hibernate.cfg.Configuration.add(Configuration.java:470)
    at org.hibernate.cfg.Configuration.add(Configuration.java:643)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:726)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2102)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2074)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2054)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2007)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1922)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1901)
    at com.cluster.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
    ... 1 more
Caused by: org.dom4j.DocumentException: Error on line 28 of document  : Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character. Nested exception: Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)
    ... 12 more

hibernate.cfg.xml:

 <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
              "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>

        <session-factory>
            <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
            <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
            <property name="connection.username">julyaugust</property>
            <property name="connection.password">julyaugust</property>
            <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
            <property name="show_sql">true</property>

            <mapping resource="com/cluster/entity/employee.hbm.xml"/>
            <mapping resource="com/cluster/entity/department.hbm.xml"/>
            <mapping resource="com/cluster/entity/addressDetails.hbm.xml"/>
            <mapping resource="com/cluster/entity/addressType.hbm.xml"/>
            <mapping resource="com/cluster/entity/city.hbm.xml"/>
            <mapping resource="com/cluster/entity/state.hbm.xml"/>
            <mapping resource="com/cluster/entity/email.hbm.xml"/>
            <mapping resource="com/cluster/entity/emailType.hbm.xml"/>
            <mapping resource="com/cluster/entity/phone.hbm.xml"/>
            <mapping resource="com/cluster/entity/phoneType.hbm.xml"/>
        </session-factory>

    </hibernate-configuration>

employee.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE hibernate-mapping PUBLIC
            '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
            'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>


             <hibernate-mapping package="com.cluster.entity" >
            <class name="Employee" table="EMPLOYEE">
            <id name="intEmployeeID" column="EMPLOYEE_ID"> 
                <generator class="sequence">
                    <param name="sequence">EMPLOYEE_ID_SEQ</param>
                </generator>
            </id>

            <property name="strFirstName" column = "FIRSTNAME"/>
            <property name="strLastName" column="LASTNAME"/>
            <property name="strDateOfBirth" column="DATE_OF_BIRTH"/>
            <property name="strSalary" column="SALARY"/>

            <many-to-one name="department" column="DEPARTMENT_ID" not-null = "true"          class = "Department"/>

            <set name="setAddressDetails" cascade="all" lazy="true">
                <key column="EMPLOYEE_ID" not-null="true"></key>
                <one-to-many class="AddressDetails"/>
            </set>

            <set name="setPhones" cascade="all" lazy="true">
                <key column="EMPLOYEE_ID" not-null="true" cas></key>
                <one-to-many class="Phone"/>
            </set>

            <set name="seEmails" cascade="all" lazy="true" >
                <key column="EMPLOYEE_ID" not-null="true"></key>
                <one-to-many class="Email"/>
            </set>

        </class>

           </hibernate-mapping>

I am using the latest jars for hibernate. (i.e. hibernate-release-4.0.1.Final )
In the previous versions i was getting proper output.
I replaced the hibernate jars and there was a exception.

org.hibernate.InvalidMappingException: Unable to read XML

I read some blogs and changed the doctype to

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

Still the error persists.

i am attaching my cfg.xml and one of my hbm.xml (as all 10 cant be attached)

Plez let me what is the problem and what should be the solution.
Thank you

Error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.cluster.action.Action.main(Action.java:19)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:106)
    at org.hibernate.cfg.Configuration.add(Configuration.java:474)
    at org.hibernate.cfg.Configuration.add(Configuration.java:470)
    at org.hibernate.cfg.Configuration.add(Configuration.java:643)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:726)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2102)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2074)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2054)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2007)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1922)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1901)
    at com.cluster.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
    ... 1 more
Caused by: org.dom4j.DocumentException: Error on line 28 of document  : Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character. Nested exception: Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:76)
    ... 12 more

hibernate.cfg.xml :

 <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
              "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

    <hibernate-configuration>

        <session-factory>
            <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
            <property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
            <property name="connection.username">julyaugust</property>
            <property name="connection.password">julyaugust</property>
            <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
            <property name="show_sql">true</property>

            <mapping resource="com/cluster/entity/employee.hbm.xml"/>
            <mapping resource="com/cluster/entity/department.hbm.xml"/>
            <mapping resource="com/cluster/entity/addressDetails.hbm.xml"/>
            <mapping resource="com/cluster/entity/addressType.hbm.xml"/>
            <mapping resource="com/cluster/entity/city.hbm.xml"/>
            <mapping resource="com/cluster/entity/state.hbm.xml"/>
            <mapping resource="com/cluster/entity/email.hbm.xml"/>
            <mapping resource="com/cluster/entity/emailType.hbm.xml"/>
            <mapping resource="com/cluster/entity/phone.hbm.xml"/>
            <mapping resource="com/cluster/entity/phoneType.hbm.xml"/>
        </session-factory>

    </hibernate-configuration>

employee.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE hibernate-mapping PUBLIC
            '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
            'http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>


             <hibernate-mapping package="com.cluster.entity" >
            <class name="Employee" table="EMPLOYEE">
            <id name="intEmployeeID" column="EMPLOYEE_ID"> 
                <generator class="sequence">
                    <param name="sequence">EMPLOYEE_ID_SEQ</param>
                </generator>
            </id>

            <property name="strFirstName" column = "FIRSTNAME"/>
            <property name="strLastName" column="LASTNAME"/>
            <property name="strDateOfBirth" column="DATE_OF_BIRTH"/>
            <property name="strSalary" column="SALARY"/>

            <many-to-one name="department" column="DEPARTMENT_ID" not-null = "true"          class = "Department"/>

            <set name="setAddressDetails" cascade="all" lazy="true">
                <key column="EMPLOYEE_ID" not-null="true"></key>
                <one-to-many class="AddressDetails"/>
            </set>

            <set name="setPhones" cascade="all" lazy="true">
                <key column="EMPLOYEE_ID" not-null="true" cas></key>
                <one-to-many class="Phone"/>
            </set>

            <set name="seEmails" cascade="all" lazy="true" >
                <key column="EMPLOYEE_ID" not-null="true"></key>
                <one-to-many class="Email"/>
            </set>

        </class>

           </hibernate-mapping>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2025-01-14 19:58:24

从您附加的日志中检查一下

        <set name="setPhones" cascade="all" lazy="true">
            <key column="EMPLOYEE_ID" not-null="true" **cas**></key>
            <one-to-many class="Phone"/>
        </set>

“来自日志与元素类型“key”关联的属性名称“cas”必须后跟“=”字符。嵌套异常:与元素类型“key”关联的属性名称“cas”后面必须跟有“=”字符。”
是问题的原因。

“没有名为“cas”的属性。

Check this out

        <set name="setPhones" cascade="all" lazy="true">
            <key column="EMPLOYEE_ID" not-null="true" **cas**></key>
            <one-to-many class="Phone"/>
        </set>

From the log you attached " from log Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character. Nested exception: Attribute name "cas" associated with an element type "key" must be followed by the ' = ' character."
is the cause of the problem.

"there is no attribute called "cas".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文