实体映射:从hbm.xml转换为orm.xml,缺少字段和属性

时间:2011-12-22 10:47:37

标签: hibernate jpa orm mapping hbm

我是hibernate的新手,我必须将应用程序中的实体映射从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和generator类?

我也没有找到与属性unique-key,type和many-to-one索引等效的内容 那么鉴别器和typedef名称=“...”class =“...”param ... /&gt; ... /&GT; ??

我会感恩,任何帮助都会很棒。

0 个答案:

没有答案
相关问题