Example: Hibernate Mapping
To facilitate migration of order entity data in the Footwear Orders sample MAPPER data report,
MJ creates the FOOTWEAR_ORDER_LINEITEM
table and
FootwearOrderLineitem
entity class.
The Hibernate mapping XML that ties the persistent entity class and table together (via Object
Relational Mapping) is shown below:
FootwearOrderLineitem.hbm.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping auto-import="true" default-lazy="false" default-access="property" default-cascade="none"> <typedef name="shoeType" class="com.arsi.mj.maprpt.entity.GenericEnumUserType"> <param name="enumClass">com.arsi.mj.testapp.hibgen.enums.ShoeType</param> <param name="identifierMethod">asName</param> <param name="valueOfMethod">asValueOf</param> </typedef> <typedef name="shoeGender" class="com.arsi.mj.maprpt.entity.GenericEnumUserType"> <param name="enumClass">com.arsi.mj.testapp.hibgen.enums.ShoeGender</param> <param name="identifierMethod">asName</param> <param name="valueOfMethod">asValueOf</param> </typedef> <class table="FOOTWEAR_ORDER_LINEITEM" name="com.arsi.mj.testapp.hibgen.model.FootwearOrderLineitem"> <meta attribute="generated-class">com.arsi.mj.testapp.hibgen.model.FootwearOrderLineitem</meta> <meta attribute="scope-field">protected</meta> <meta attribute="class-description">Persistent class for Mapper report 12D3954 (FootWear - Orders Information) after conversion to database table <code>FOOTWEAR_ORDER_LINEITEM</code>. </meta> <id unsaved-value="null" type="long" column="fw_order_li_id" name="id"> <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator"> <param name="sequence_name">SEQ_FOOTWEAR_ORDER_LINEITEM</param> <param name="initial_value">1000</param> <param name="increment_size">1</param> </generator> </id> <property type="integer" name="orderNumber"> <meta attribute="field-description">Entity attribute for MAPPER report column OrdNo.</meta> <column not-null="true" length="5" name="order_no"/> </property> <property type="integer" name="quantity"> <meta attribute="field-description">Entity attribute for MAPPER report column Qty.</meta> <column not-null="true" length="3" name="QTY"/> </property> <property type="shoeType" name="shoeType"> <meta attribute="property-type">com.arsi.mj.testapp.hibgen.enums.ShoeType</meta> <meta attribute="field-description">Entity attribute for MAPPER report column Type.</meta> <column sql-type="varchar2(5)" not-null="true" length="5" name="SHOE_TYPE"/> </property> <property type="shoeGender" name="shoeGender"> <meta attribute="property-type">com.arsi.mj.testapp.hibgen.enums.ShoeGender</meta> <meta attribute="field-description">Entity attribute for MAPPER report column Gender.</meta> <column sql-type="varchar2(1)" not-null="true" length="1" name="SHOE_GENDER"/> </property> <property type="string" name="shoeSize"> <meta attribute="field-description">Entity attribute for MAPPER report column Siz.</meta> <column not-null="true" length="3" name="SHOE_SIZE"/> </property> <property type="string" name="shoeColor"> <meta attribute="field-description">Entity attribute for MAPPER report column Color.</meta> <column not-null="false" length="40" name="SHOE_COLOR"/> </property> <property type="big_decimal" name="price"> <meta attribute="field-description">Entity attribute for MAPPER report column Price.</meta> <column not-null="true" scale="2" precision="8" name="PRICE"/> </property> <property type="date" name="dateOrdered"> <meta attribute="field-description">Entity attribute for MAPPER report column Date.</meta> <column not-null="true" length="8" name="ORDER_DATE"/> </property> <property type="string" name="timeOrdered"> <meta attribute="field-description">Entity attribute for MAPPER report column Time.</meta> <column not-null="true" length="5" name="ORDER_TIME"/> </property> <property type="big_decimal" name="cost"> <meta attribute="field-description">Entity attribute for MAPPER report column Cost.</meta> <column not-null="false" scale="2" precision="8" name="COST"/> </property> <properties name="audit"> <property type="timestamp" name="createTimestamp"> <meta attribute="field-description">Entity attribute containing time of row creation.</meta> <column not-null="true" name="create_timestamp"/> </property> <property type="timestamp" name="lastUpdateTimestamp"> <meta attribute="field-description">Entity attribute containing time of last row update.</meta> <column not-null="true" name="DATE_OF_LAST_UPDATE"/> </property> <property type="java.lang.Long" name="createUserId"> <meta attribute="field-description">Entity attribute containing user who created row.</meta> <column not-null="true" name="CREATED_BY_USER"/> </property> <property type="java.lang.Long" name="lastUpdateUserId"> <meta attribute="field-description">Entity attribute containing user who last updated row.</meta> <column not-null="true" name="update_user_id"/> </property> </properties> <join optional="true" inverse="true" table="MJ_FOOTWEAR_ORDER_LINEITEM"> <key column="fw_order_li_id"/> <component name="lineMetadata" class="com.arsi.mj.testapp.hibgen.model.MJFootwearOrderLineitem"> <meta attribute="generated-class">com.arsi.mj.testapp.hibgen.model.MJFootwearOrderLineitem</meta> <property insert="false" update="false" column="fw_order_li_id" type="long" name="id"/> <property column="MJ_CABINET" type="int" name="cabinet"/> <property column="MJ_DRAWER" type="char" name="drawer"/> <property column="MJ_REPORT" type="int" name="report"/> <property column="MJ_LINETYPE" type="char" name="lineType"/> </component> </join> <join optional="true" inverse="true" table="FOOTWEAR_ORDER_ADDRESSEE"> <key column="fw_order_li_id"/> <component name="footwearOrderAddressee" class="com.arsi.mj.testapp.hibgen.model.FootwearOrderAddressee"> <meta attribute="generated-class">com.arsi.mj.testapp.hibgen.model.FootwearOrderAddressee</meta> <property insert="false" update="false" column="fw_order_li_id" type="long" name="id"/> <property column="ADDRESSEE" type="string" name="addressee"/> <property column="STREET" type="string" name="street"/> <property column="CITY_STATE_PROVINCE" type="string" name="cityState"/> <property column="POSTAL_CODE" type="string" name="postalCode"/> <property column="EMAIL" type="string" name="email"/> <property column="PHONE" type="string" name="phone"/> </component> </join> </class> </hibernate-mapping>