我用的是Hibernate 6.1.4
和Jakarta Persistence 3.1
和JDK 11.0.16.1+1.
支持<hibernate-mappings>
是不可取的,所以当我在hibernate.cfg
中配置"hibernate.transform_hbm_xml.enabled"
时,它会抛出一个异常。
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
<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
<?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
<?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
这个例外的确切原因是什么?
发布于 2022-10-11 09:44:34
该错误指出,尚未实现一对多关联的转换,因此现在必须手动转换以下映射:
<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,并对其进行评论。
https://stackoverflow.com/questions/74004291
复制相似问题