<?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>The Path to Zen &#187; hibernate</title>
	<atom:link href="http://www.digizenstudio.com/blog/categories/java/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digizenstudio.com/blog</link>
	<description>Jing Xue's Weblog</description>
	<lastBuildDate>Tue, 01 Jun 2010 01:40:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>joined-subclass with discriminator-value?</title>
		<link>http://www.digizenstudio.com/blog/2006/07/22/joined-subclass-with-discriminator-value/</link>
		<comments>http://www.digizenstudio.com/blog/2006/07/22/joined-subclass-with-discriminator-value/#comments</comments>
		<pubDate>Sat, 22 Jul 2006 23:05:49 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=102</guid>
		<description><![CDATA[So I am trying to use Hibernate to map a class hierarchy with table-per-hierarchy mixed with table-per-subclass.
I start with:
PLAIN TEXT
XML:




&#60;class name="com.packageA.SuperClass" discriminator-value="0" table="SUPER"&#62;


&#160; &#60;discriminator column="CLASS_TYPE" type="int" /&#62;


&#160; &#60;!-- ... --&#62;


&#160; &#60;subclass name="com.packageA.SubClass1" discriminator-value="1"&#62;


&#160; &#160; &#60;!-- ... --&#62;


&#160; &#60;/subclass&#62;


&#60;/class&#62; 






and to add a second SubClass2 from another package packageB, which I wish to have a join [...]]]></description>
			<content:encoded><![CDATA[<p>So I am trying to use Hibernate to map a class hierarchy with table-per-hierarchy mixed with table-per-subclass.<span id="more-102"></span></p>
<p>I start with:</p>
<div class="igBar"><span id="lxml-4"><a href="#" onclick="javascript:showPlainTxt('xml-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-4">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageA.SuperClass"</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"SUPER"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;discriminator</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"CLASS_TYPE"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"int"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;subclass</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageA.SubClass1"</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/subclass<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/class<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>and to add a second SubClass2 from another package packageB, which I wish to have a join table for the extended properties.  Now in the overall design, it's OK for packageB to depend on packageA, but not the other way around, so I want to keep SubClass2's Hibernate mapping in packageB as well.  Therefore, initially I tried, in SubClass2's own mapping file:</p>
<div class="igBar"><span id="lxml-5"><a href="#" onclick="javascript:showPlainTxt('xml-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-5">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;joined</span> -subclass <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageB.SubClass2"</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">"com.packageA.SuperClass"</span>&nbsp; <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"SUB2"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/joined<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<em>(Note: apparently there is some bug in Wordpress that mangles up the opening and closing tags for "joined-subclass". It's properly opened and closed in my actual XML code.)</em><br />
But Hibernate threw back a NumberFormatException when trying to convert a string discriminator value, "com.packageB.SubClass2", to an integer, apparently due to the fact that the joined-subclass above didn't give a discriminator value in integer, so it defaults to the class FQN.  And of course, the &lt;joined-subclass&gt; element can't have a 'discriminator-value' attribute per the DTD.</p>
<p>Now I could probably just get rid of my integer discriminator scheme and use the default class FQNs.  But I never thought class FQNs are good candidates for class type discriminator to begin with, because... well, why would I want to have to screw around in the DB running massive SQL updates just because some class is renamed?</p>
<p>So I end up sacrificing a little on the dependency rule front, and basically moved SubClass2's mapping into SuperClass's:</p>
<div class="igBar"><span id="lxml-6"><a href="#" onclick="javascript:showPlainTxt('xml-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-6">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageA.SuperClass"</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"SUPER"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;discriminator</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">"CLASS_TYPE"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"int"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;subclass</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageA.SubClass1"</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">"1"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/subclass<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;subclass</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"com.packageB.SubClass2"</span> <span style="color: #000066;">discriminator-value</span>=<span style="color: #ff0000;">"2"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;join</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">"SUB2"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/join<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/subclass<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/class<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I still can't see why joined-subclass shouldn't have that 'discriminator-value' attribute, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/07/22/joined-subclass-with-discriminator-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>persist() vs. save()</title>
		<link>http://www.digizenstudio.com/blog/2006/02/14/persist-vs-save/</link>
		<comments>http://www.digizenstudio.com/blog/2006/02/14/persist-vs-save/#comments</comments>
		<pubDate>Tue, 14 Feb 2006 19:42:06 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=87</guid>
		<description><![CDATA[Hibernate 3 added a new persist() method to the Session interface. It came from the EJB3 Entity Manager spec.  In case you are also wondering whether to migrate to it or just stick to the good old save() method to insert a new object, here's what I found out:
A discussion on Hibernate Forum
A JIRA [...]]]></description>
			<content:encoded><![CDATA[<p>Hibernate 3 added a new persist() method to the Session interface. It came from the EJB3 Entity Manager spec.  In case you are also wondering whether to migrate to it or just stick to the good old save() method to insert a new object, here's what I found out:<br />
<a href="http://forum.hibernate.org/viewtopic.php?t=951275&#038;highlight=difference+persist+save" rel="_blank">A discussion on Hibernate Forum</a><br />
<a href="http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1273" rel="_blank">A JIRA ticket</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/02/14/persist-vs-save/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Circular Bean Reference Problem in Spring 2.0&#8217;s Arbitrary Domain Object Wiring</title>
		<link>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/</link>
		<comments>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/#comments</comments>
		<pubDate>Tue, 07 Feb 2006 03:00:22 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=86</guid>
		<description><![CDATA[Spring 2.0 has an exciting new feature that, with AspectJ's powerful AOP support, allows arbitrary domain objects to be injected with dependencies at the time of creation, even when the domain object is not created by Spring. This feature helps developers avoiding the "Anemic Domain Model" because now domain objects can have references to services [...]]]></description>
			<content:encoded><![CDATA[<p>Spring 2.0 has an exciting new feature that, with AspectJ's powerful AOP support, allows arbitrary domain objects to be injected with dependencies at the time of creation, even when the domain object is not created by Spring. This feature helps developers avoiding the "Anemic Domain Model" because now domain objects can have references to services or even DAO's, instead of just some other domain objects.<span id="more-86"></span></p>
<p>This particular problem comes when I try to inject a DAO into a domain object (I know it's some debatable practice, but please just bear me for a moment).  So the DO is annotated with @Configurable, its constructor is advised such that, at runtime, after the initialization, the Spring aspect will try to get a reference to the DAO, and sets it into this new DO instance. However, in order to materialize the DAO, which naturally holds a reference to a Hibernate session factory. The session factory needs to be instantiated  first - and that, surprisingly, is when I get the "circular bean reference" meltdown.</p>
<p>After one pint of log reading, three shots of source code tracing, and a pinch of hair pulling, this here turns out to be the story: at the session factory initialization time, Hibernate3 needs to know which id value represents an unsaved object. E.g., null, -1, or whatever sensible value depending on the nature of the object and the corresponding table. This value is specified via the 'unsaved-value' attribute in the object mapping., and, as suggested by the reference, can usually be omitted safely, for Hibernate3 is very smart and can actually guess the unsaved-value by instantiating a new instance of the DO, which naturally would be intercepted by Spring and be injected with a DAO reference, which naturally would need a reference to the session factory, which naturally would have to guess what the unsaved-value is....</p>
<p>The solution is easy - just add 'unsaved-value="null"' to the mapping file, to prevent Hibernate from attemping the guess.</p>
<p>Now, I can hear you making some impatient noise - "what's all this inject-DAO-into-DO business?!"  Well, I agree it's some debatable practice, but then it's also hardly the point here.  I could well have tried to inject a service object into this DO, and the service object could have held a legit reference to some DAO. It would have been the same circular reference, only a larger circle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Call Me Pedantic &#8211; What Exactly IS Scalability?</title>
		<link>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/</link>
		<comments>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 18:36:42 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[fisheye]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=75</guid>
		<description><![CDATA[This is mostly triggered by Diego Parrilla's post Spring is not designed for scalability, in which he goes, "...Basically you have two options if you want to scale with pure web applications...", and then gives two options to scale, both of which involves state replicating clustering schemes.  There, Diego, you got on my pedantic [...]]]></description>
			<content:encoded><![CDATA[<p>This is mostly triggered by Diego Parrilla's post <a href="http://www.diegoparrilla.com/2006/01/spring-is-not-designed-for-scalability.html" rel="_blank">Spring is not designed for scalability</a>, in which he goes, "...Basically you have two options if you want to scale with pure web applications...", and then gives two options to scale, both of which involves state replicating clustering schemes.  There, Diego, you got on my pedantic nerve. <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   I can't help but wondering this question - what, exactly is Scalability?<span id="more-75"></span></p>
<p>So I went on and did a bit research (OK, OK, I really just googled "define: Scalability"), and got  <a href="http://www.google.com/search?num=20&#038;hl=en&#038;hs=NXC&#038;lr=&#038;c2coff=1&#038;client=firefox-a&#038;rls=org.mozilla:en-US:official&#038;oi=defmore&#038;defl=en&#038;q=define:Scalability" rel="_blank">these definitions</a>. Let me just quote the first three here:</p>
<blockquote><p>The ability to scale to support larger or smaller volumes of data and more or less users. The ability to increase or decrease size or capability in cost-effective increments with minimal impact on the unit cost of business and the procurement of additional services. - dmreview.com</p></blockquote>
<blockquote><p>The ability and flexibility of an application to meet growth requirements of an organization. - hostqueue.com</p></blockquote>
<blockquote><p>The ability to expand a computing solution to support large numbers of users without impacting performance. - primode.com</p></blockquote>
<p>So scalability is about performance - the capability to handle large volume of traffic, as far as web applications go.  It does not have anything to do with "miminal service interruption when one of the servers goes down" - that's <a href="http://www.ieeetfcc.org/high-availability.html" rel="_blank">High Availability</a>.  It especially does not have anything to do with "<em>no</em> service interruption whatsoever" - that's Continuous Availability (see the last link). We usually don't need the expensive state-replicating schemes to achieve Scalability, or even High Availability.  A sticky-session load balancer and a server farm without busily replicating sessions among themselves would scale well, and would provide some pretty high availability.  It can't provide Continuous Availability because when a server fails all the users on that server at that point would have lost their sessions.  That's the only case where clustering comes in and support immediate fail-over without any interruption to the service.</p>
<p>Now, the real question for all you architects out there that can't wait to hop on the "clustering wagon" the second you hear "scalability" is, is your application really "mission-critical" enough, meaning no user can ever lose her session, to justify the cost to implementing clustering?  Remember the cost here includes not only the performance penalty (ironic isn't it), but also the development penalties - you'll have to make sure that whatever you stick in the session implements the Serializable interface, that whatever you stick in there references does the same, and finally that not too much is stuck in there.</p>
<p>On a separate level, I don't necessarily agree with Diego's comment (his main point actually) on Spring being not scalable, either.   The fallacy here, IMHO, is the same as what I have seen from a lot of other online discussions.  It's that people keep trying to compare Spring with EJB, forgetting they are different things and meant for different things.</p>
<p>What is Spring?  Even though we all refer to Spring as a <em>container</em>, we have to remember that it's a completely different kind of container from the kind EJB is.  Spring is a <em>bean container</em>, or rather more accurately, as the name of one of its core interfaces shows, it is a <em>bean factory</em>.  All Spring does is providing us the ability to transparently wire up our applications, and the convenience to easily integrate with lots of third-part tools, but Spring does not reinvent the wheels by reimplementing those tools on itself.  E.g., Spring provides easy integration with well-known ORM tools such as Hibernate and iBatis, rather than providing it own ORM package.  On the other hand, EJB is a <em>container</em> in the real sense of "All Your Base Are Belong To Us" <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  It provides a complete solution with a more restrictive programming paradiam.  Spring is not mutually exclusive with EJB, nor is it a competitor of the latter one.  You can use Spring to wire up an EJB-based service layer just as easy as you do, say, a Hessian-based one.  Comparing Spring to EJB is like comparing apple and orange.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Property Or Field Access?</title>
		<link>http://www.digizenstudio.com/blog/2005/05/15/property-or-field-access/</link>
		<comments>http://www.digizenstudio.com/blog/2005/05/15/property-or-field-access/#comments</comments>
		<pubDate>Sun, 15 May 2005 20:11:00 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=46</guid>
		<description><![CDATA[Some ongoing thoughts on the pros and cons of property access vs. field access in hibernate.]]></description>
			<content:encoded><![CDATA[<p>Hibernate supports access objects attributes through Java Bean accessor methods or direct field access through reflection.  You can also supply your own PropertyAccessor implementation, but in this post I'll leave that aside and focus on comparing the first two approaches.<span id="more-46"></span></p>
<p>So here are the pros of property access I can think of:</p>
<ul>
<li>It conforms to the OO encapsulation principle. This is also the reason that property access is the preferred strategy by the Hibernate team (as discussed in <em>Hibernate In Action</em> and implied by it being the default accessing strategy in mapping file definitions).</li>
<li>It provides a subclass the possibility to override a property accessor.</li>
<li>Field access assumes a SecurityManager not restricting access to private instance variables.  In most of cases this is a valid assumption - if an application needs to worry about others running in the same JVM peeking into its private fields, it should probably get its own JVM.  But still, property access does not have this kind of restriction.</li>
</ul>
<p>Now the pros of field access:</p>
<ul>
<li>Field access allows to bypass an accessor that has more logic in it than simple value getting/setting. If we want to achieve direct mapping between database and domain objects (rather than DTOs), this can be very useful because most of the time the extra logic added is business logic, and should not or need not be applied at persistence time.</li>
<li>Field access eliminates the need to define an accessor that does not make sense in the domain model, but just for the sake of populating the field at persistence time. The most typical example is the primary key field in every "Hibernated" objects, which usually should never be changed through out the object's lifetime.  From the architecture standpoint, this is also a strong argument for the field access approach because it prevents the leakage of concerns from the data access layer into the domain model.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/05/15/property-or-field-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

