首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >配置"hibernate.transform_hbm_xml.enabled“引发异常

配置"hibernate.transform_hbm_xml.enabled“引发异常
EN

Stack Overflow用户
提问于 2022-10-09 11:18:07
回答 1查看 44关注 0票数 0

我用的是Hibernate 6.1.4Jakarta Persistence 3.1JDK 11.0.16.1+1.

支持<hibernate-mappings>是不可取的,所以当我在hibernate.cfg中配置"hibernate.transform_hbm_xml.enabled"时,它会抛出一个异常。

代码语言:javascript
运行
复制
Initial SessionFactory creation failed.org.hibernate.boot.InvalidMappingException: Could not parse mapping document: com/retailfx/pojo/Items.hbm.xml (RESOURCE)  

Caused by: org.hibernate.boot.InvalidMappingException: Could not parse mapping document: com/retailfx/pojo/Items.hbm.xml (RESOURCE)  

Caused by: org.hibernate.boot.MappingException: OneToMany transformation not yet implemented : origin(com/retailfx/pojo/Items.hbm.xml)

hibernate.cfg

代码语言:javascript
运行
复制
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
        <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
        <property name="hibernate.connection.url">jdbc:derby://localhost:1527/retailfx</property>
        <property name="hibernate.connection.username">app</property>
        <property name="hibernate.connection.password">derby</property>
        <property name="hibernate.default_catalog"/>
           
        <property name="hibernate.transform_hbm_xml.enabled">true</property>
        
        <mapping resource="com/retailfx/pojo/Items.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Items.hbm.xml

代码语言:javascript
运行
复制
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.retailfx.pojo.Items" table="ITEMS" schema="APP" optimistic-lock="version">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="itemname" type="string">
            <column name="ITEMNAME" length="100" not-null="true" />
        </property>
        <property name="cost" type="string">
            <column name="COST" length="100" not-null="true" />
        </property>
        <property name="quantity" type="string">
            <column name="QUANTITY" length="100" not-null="true" />
        </property>
        <set name="saleses" table="SALES" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="ITID" not-null="true" />
            </key>
            <one-to-many class="com.retailfx.pojo.Sales" />
        </set>
    </class>
</hibernate-mapping>  

Sales.hbm.xml

代码语言:javascript
运行
复制
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.retailfx.pojo.Sales" table="SALES" schema="APP" optimistic-lock="version">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
       
        <many-to-one name="items" class="com.retailfx.pojo.Items" fetch="select">
            <column name="ITID" not-null="true" />
        </many-to-one>
        <property name="itemname" type="string">
            <column name="ITEMNAME" length="100" not-null="true" />
        </property>
        <property name="cost" type="string">
            <column name="COST" length="100" not-null="true" />
        </property>
        <property name="quantity" type="string">
            <column name="QUANTITY" length="100" not-null="true" />
        </property>
        <property name="total" type="string">
            <column name="TOTAL" length="100" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

我不使用@annotations

这个例外的确切原因是什么?

EN

回答 1

Stack Overflow用户

发布于 2022-10-11 09:44:34

该错误指出,尚未实现一对多关联的转换,因此现在必须手动转换以下映射:

代码语言:javascript
运行
复制
        <set name="saleses" table="SALES" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="ITID" not-null="true" />
            </key>
            <one-to-many class="com.retailfx.pojo.Sales" />
        </set>

还可以在问题跟踪器(https://hibernate.atlassian.net)中使用再现问题的测试用例(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)创建问题。

您还可以跟踪现有的增强请求https://hibernate.atlassian.net/browse/HHH-15334,并对其进行评论。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74004291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档