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

Hibernate example source code file (discrim-subclass.hbm.xml)

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

case, doctype, dtd, employee, employee, end, jboss, mapping, person, sperson, then, then, when, when

The Hibernate discrim-subclass.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.subclassfilter">

	<class name="Person" discriminator-value="0" table="SPerson">

		<id name="id" column="person_id">
			<generator class="native"/>
		</id>

		<discriminator type="int"
			formula="CASE WHEN company is null THEN 0 WHEN company = 'JBoss' THEN 1 ELSE 2 END"/>

		<property name="name"/>
		<property name="company"/>
		<property name="region"/>

		<subclass name="Employee" discriminator-value="1">
			<property name="title"/>
			<property name="department" column="dept"/>
			<many-to-one name="manager" column="mgr_id" class="Employee" cascade="none"/>
			<set name="minions" inverse="true" lazy="true" cascade="all">
				<key column="mgr_id"/>
				<one-to-many class="Employee"/>
				<filter name="region" condition="region = :userRegion"/>
			</set>
		</subclass>

		<subclass name="Customer" discriminator-value="2">
			<many-to-one name="contactOwner" class="Employee"/>
		</subclass>

		<filter name="region" condition="region = :userRegion"/>

	</class>

	<filter-def name="region">
		<filter-param name="userRegion" type="string"/>
    </filter-def>

</hibernate-mapping>

Other Hibernate examples (source code examples)

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