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

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

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

address, address, billingaddress, billingaddress, customer, doctype, dtd, hibernate/hibernate, mapping, shippingaddress, shippingaddress, shows, the, we

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

<!--

	Shows how to map a one-to-many relationship in the relational
	schema to "typed" one-to-one associations in the object model.
	We map the Address class twice, with different entity names,
	specifying a filtering condition in each mapping. The typed
	associations then reference the named entities.

-->

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

	<class name="Customer" 
			select-before-update="true" 
			dynamic-update="true">
	
		<id name="customerId">
			<generator class="assigned"/>
		</id>
	
		<property name="name" not-null="true"/>
		
		<many-to-one name="billingAddress" 
			entity-name="BillingAddress"
			cascade="persist,save-update,delete"
			fetch="join">
			<column name="billingAddressId"/>
			<formula>'BILLING'
		</many-to-one>
			
		<many-to-one name="shippingAddress" 
			entity-name="ShippingAddress"
			cascade="persist,save-update,delete"
			fetch="join">
			<column name="shippingAddressId"/>
			<formula>'SHIPPING'
		</many-to-one>
			
	</class>
	
	<class name="Address"
		table="Address"
		entity-name="BillingAddress" 
		where="add_type='BILLING'" 
		check="add_type in ('BILLING', 'SHIPPING')"
		select-before-update="true" 
		dynamic-update="true">
	
		<composite-id name="addressId"> 
			<key-property name="addressId"/>
			<key-property name="type" column="add_type"/>
		</composite-id>
		
		<property name="street" not-null="true"/>
		<property name="city" not-null="true"/>
		<property name="state" not-null="true"/>
		<property name="zip" not-null="true"/>
						
	</class>

	<class name="Address" 
		table="Address"
		entity-name="ShippingAddress"
		where="add_type='SHIPPING'"
		select-before-update="true" 
		dynamic-update="true">
	
		<composite-id name="addressId">
			<key-property name="addressId"/>
			<key-property name="type" column="add_type"/>
		</composite-id>
		
		<property name="street" not-null="true"/>
		<property name="city" not-null="true"/>
		<property name="state" not-null="true"/>
		<property name="zip" not-null="true"/>
						
	</class>

</hibernate-mapping>

Other Hibernate examples (source code examples)

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