gpt4 book ai didi

hibernate - hbm.xml 文件中出现一些错误

转载 作者:行者123 更新时间:2023-12-02 09:36:38 24 4
gpt4 key购买 nike

我是 hibernte 新手。我正在尝试使用 hibernate 从 oracle 表中简单检索记录。

我的实体类名为pojo1,pojo1.hbm.xml如下:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="hibernate" default-lazy="true">

<class name="pojo1" table="QUOTE_MESSAGE_TRANSLATION_BKP">
<meta attribute="class-description">
</meta>
<property name="id" column="TRANSLATION_ID" type="java.lang.Integer"/>
<property name="commitCode" column="COMMIT_CODE" type="java.lang.Integer"/>
</class>
</hibernate-mapping>

我在运行包含所有事务代码的应用程序类时收到以下错误:

... ...
INFO: HHH000221: Reading mappings from resource: pojo1.hbm.xml
Aug 26, 2014 10:32:28 AM org.hibernate.internal.util.xml.ErrorLogger logErrors
ERROR: HHH000196: Error parsing XML (3) : The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite- id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
Aug 26, 2014 10:32:28 AM org.hibernate.internal.util.xml.ErrorLogger logErrors
ERROR: HHH000196: Error parsing XML (3) : The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Unable to read XML
Exception in thread "main" java.lang.ExceptionInInitializerError
at hibernate.app.main(app.java:20)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304)
at org.hibernate.cfg.Configuration.add(Configuration.java:516)
at org.hibernate.cfg.Configuration.add(Configuration.java:512)
at org.hibernate.cfg.Configuration.add(Configuration.java:686)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:769)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)
at hibernate.app.main(app.java:17)
Caused by: org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 12; The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at .... ....

请帮忙。

最佳答案

您必须声明 id对于您的实体类,使用 <id>标签。

所以改变这个:

<property name="id" column="TRANSLATION_ID" type="java.lang.Integer"/>

对此:

<id name="id" column="TRANSLATION_ID" type="int"></id>

关于hibernate - hbm.xml 文件中出现一些错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25498490/

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