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

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

This example Hibernate source code file (Order.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

customerorder, doctype, dtd, hibernate/hibernate, id, lineitem, lineitem, mapping, mapping, order, order, product, product, this

The Hibernate Order.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">

<hibernate-mapping package="org.hibernate.test.cid">

<!-- 

  This mapping demonstrates 
  
     (1) composite keys and one-to-many associations on 
         composite keys
      
     (2) use of insert="false" update="false" on an
         association mapping, when the foreign key is
         also part of the primary key
         
     (3) use of a derived property which performs a
         subselect against associated tables
         
     (4) use of <synchronize/> to ensure that auto-flush
         works correctly for an entity with a property
         derived from other tables
         
     
-->

    <class name="Order" table="CustomerOrder">
    	<synchronize table="LineItem"/>
    	<synchronize table="Product"/>
    	
    	<composite-id name="id" 
    		class="Order$Id">
    		<key-property name="customerId" length="10"/>
    		<key-property name="orderNumber"/>
    	</composite-id>
    	
    	<property name="orderDate" 
    		type="calendar_date"
    		not-null="true"/>
    	
    	<property name="total" 
    		formula="( select sum(li.quantity*p.cost) from LineItem li, Product p where li.productId = p.productId and li.customerId = customerId and li.orderNumber = orderNumber )"/>
    	
    	<many-to-one name="customer"
    		column="customerId"
    		insert="false"
			update="false" 
			not-null="true"/>
			
    	<bag name="lineItems"
    		fetch="join" 
    		lazy="false"
    		inverse="true"
    		cascade="save-update">
    		<key>
    			<column name="customerId"/>
    			<column name="orderNumber"/>
    		</key>
    		<one-to-many class="LineItem"/>
    	</bag>
    	
    </class>
 	
</hibernate-mapping>

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Order.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.