<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>devblog @ x-sphere.com &#187; discriminator</title>
	<atom:link href="http://devblog.x-sphere.com/tag/discriminator/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.x-sphere.com</link>
	<description>random babblings of a product manager and coder</description>
	<lastBuildDate>Wed, 16 May 2012 17:48:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20766</generator>
		<item>
		<title>hibernate and subclasses</title>
		<link>http://devblog.x-sphere.com/2006/11/02/hibernate-and-subclasses/</link>
		<comments>http://devblog.x-sphere.com/2006/11/02/hibernate-and-subclasses/#comments</comments>
		<pubDate>Thu, 02 Nov 2006 15:56:26 +0000</pubDate>
		<dc:creator>Matt Brotherson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[data access objects]]></category>
		<category><![CDATA[discriminator]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[subclasses]]></category>

		<guid isPermaLink="false">http://devblog.x-sphere.com/index.php/2006/11/02/hibernate-and-subclasses/</guid>
		<description><![CDATA[Another challenge that presented us in developing our current product was persistence. Upon the recommendation of our architect, we chose Hibernate. Hibernate is a great tool for persisting model objects to nearly any data source you could imagine. The base implementation with our Data Access Objects (DAO&#8217;s) was straight forward. We didn&#8217;t want to create [...]]]></description>
			<content:encoded><![CDATA[<p>Another challenge that presented us in developing our current product was persistence.  Upon the recommendation of our architect, we chose Hibernate.  Hibernate is a great tool for persisting model objects to nearly any data source you could imagine.  The base implementation with our Data Access Objects (DAO&#8217;s) was straight forward.</p>
<p>We didn&#8217;t want to create an overly large schema for storing objects so when we started getting into subclasses we looked for a solution to handle subclasses and store them in the same table as the superclass.  Luckily Hibernate can handle this as well.  The only downside to our approach was that we ended up with a table that has columns for all the properties of each subclass with not-null set to false.  This means your data integrity will have to reside in your manager objects.</p>
<p><span id="more-6"></span></p>
<p>An example hibernate mapping for a super/subclass relationship looks like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-mapping PUBLIC
&quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;
&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;

&lt;hibernate-mapping&gt;
&lt;class name=&quot;somepackage.model.DataItem&quot; table=&quot;DATA_ITEM&quot; polymorphism=&quot;implicit&quot;&gt;
&lt;id name=&quot;id&quot; column=&quot;DATA_ITEM_ID&quot; unsaved-value=&quot;0&quot;&gt;
&lt;!-- The &quot;increment&quot; generator would hose us in a clustered environment. --&gt;
&lt;generator class=&quot;increment&quot; /&gt;
&lt;/id&gt;
&lt;discriminator column=&quot;DISCRIMINATOR&quot; type=&quot;string&quot; /&gt;

&lt;subclass name=&quot;somepackage.model.ReportDataItem&quot; discriminator-value=&quot;Report&quot; /&gt;

&lt;subclass name=&quot;somepackage.model.KpiDataItem&quot; discriminator-value=&quot;KPI&quot;&gt;
&lt;property name=&quot;symbolID&quot; column=&quot;SYMBOL_ID&quot; not-null=&quot;false&quot; /&gt;
&lt;/subclass&gt;

&lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p>As you can see &#8211; set the polymorphism attribute to implicit and use the  tags to create the mapping.  You also need to define the discriminator to tell Hibernate what class to instantiate.  In your DAO&#8217;s, pull back a list collection and you will have a collection of instances of classes based on your mapping.</p>
]]></content:encoded>
			<wfw:commentRss>http://devblog.x-sphere.com/2006/11/02/hibernate-and-subclasses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

