我是休眠新手,我必须将应用程序中的实体映射从 hbm.xml 转换为 orm.xml。我的问题是我缺少一些正确转换的字段和属性。
这是我要转换的 hbm.xml:
<hibernate-mapping package="server.model.history">
<typedef name="outputType" class="org.hibernate.type.EnumType">
<param name="enumClass">server.model.history.OutputType</param>
<!-- Hibernate type '4' means Integer -->
<param name="type">4</param>
</typedef>
<class name="ProcessOutput" table="PROCESS_OUTPUT" mutable="false">
<id name="id" column="ID" type="server.model.id.hibernate.ProcessOutputIdUserType" access="field">
<generator class="info.novatec.np.server.model.id.hibernate.CustomGenerator" />
</id>
<discriminator column="HOST_KIND" type="string"/>
<version name="version"
access="field"
column="VERSION"
type="integer"/>
<property name="sequence" column="SEQUENCE" type="integer" not-null="true" unique-key="UNIQUE_SEQUENCE_CREATED_PROCESSID" access="field"/>
<list name="variables" table="HOST_VARIABLE" cascade="all">
<key column="FK_HOST_ID"/>
<list-index column="INDEX" />
<composite-element class="server.model.SimpleKeyValuePair">
<property name="key" access="field" column="KEY" type="string" not-null="true" />
<property name="value" access="field" column="VALUE" type="string"/>
</composite-element>
</list>
<many-to-one name="process" class="ProcessStep" column="FK_PROCESS_ID" not-null="true" unique-key="UNIQUE_SEQUENCE_CREATED_PROCESSID" access="field" index="OUTPUT_FOREIGNKEY_INDEX" />
</class>
</hibernate-mapping>
到目前为止,这是我将其转换为 orm.xml 的方法:
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
version="1.0">
<package>info.novatec.np.server.model.history</package>
<entity class="ProcessOutput">
<table name="PROCESS_OUTPUT" />
<attributes>
<id name="id">
<column name="ID" />
</id>
<version name="version" ><column name="VERSION"/></version>
<basic name="sequence">
<column name="SEQUENCE" nullable="false"/>
</basic>
<many-to-one name="process" ></many-to-one>
</attributes>
</entity>
</entity-mappings>
如您所见,它不完整、杂乱无章且部分不正确。如何在 orm.xml 中编写 id_type id_access 和生成器类?
我也没有找到与属性唯一键、类型和多对一索引等价的东西,以及鉴别器和 typedef name="..." class="..." param.../> 怎么样。 ../>??
我会很感激,如果有任何帮助都会很棒。