alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (EagerMapping.hbm.xml)

This example Hibernate source code file (EagerMapping.hbm.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

comp_lazy_km2o_cust, cust_id, cust_id, customer, customer, doctype, dtd, id, id, item_desc, mapping, order, order, ordr_num

The Hibernate EagerMapping.hbm.xml source code

<?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">

<!--
    This mapping demonstrates the use of composite ids with the
    key-many-to-one feature.  Essentially a composite id where part
    of the composition is a foreign-key to another entity.

    Here, specifically, we map the key-many-to-one as a lazy
    association.
-->

<hibernate-mapping package="org.hibernate.test.keymanytoone.bidir.component">

    <class name="Customer" table="COMP_LAZY_KM2O_CUST">
        <id name="id" column="ID" type="long">
            <generator class="increment" />
        </id>
        <property name="name" column="NAME" type="string" />
        <bag name="orders" inverse="true" cascade="all" lazy="false" fetch="join">
            <key column="CUST_ID" />
            <one-to-many class="Order" />
        </bag>
    </class>

    <class name="Order" table="COMP_LAZY_KM2O_ORDR">
        <composite-id name="id" class="Order$Id">
            <key-many-to-one name="customer" class="Customer" column="CUST_ID" lazy="false"/>
            <key-property name="number" column="ORDR_NUM" type="long" />
        </composite-id>
        <set name="items" table="COMP_LAZY_KM2O_ITEM">
            <key>
                <column name="CUST_ID"/>
                <column name="ORDER_NUM"/>
            </key>
            <element type="string" column="ITEM_DESC" />
        </set>
    </class>

</hibernate-mapping>

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate EagerMapping.hbm.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.