<?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>let x=x &#187; jpa</title>
	<atom:link href="http://www.crazymcphee.net/x/tag/jpa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crazymcphee.net/x</link>
	<description>programming idiom and methodology</description>
	<lastBuildDate>Tue, 13 Jul 2010 21:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ORM-is-Dead meme</title>
		<link>http://www.crazymcphee.net/x/2009/10/19/orm-is-dead-meme/</link>
		<comments>http://www.crazymcphee.net/x/2009/10/19/orm-is-dead-meme/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 07:31:32 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tools and techniques]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dao]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[persistence]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=488</guid>
		<description><![CDATA[I agree with Stephan, and  Aldo; ORMs increasingly get in the way. Collection mapping is one of those &#8220;hello world&#8221; problems. (The &#8220;hello world&#8221; example in the doco looks totally trivial and completely ideal [which is the problem], but suck-in-the-galaxy-greet-it-and-then-map-all-the-stars problem, which is more like what your real app looks like, is far less than [...]]]></description>
			<content:encoded><![CDATA[<p>I agree with <a href="http://codemonkeyism.com/orms/">Stephan</a>, and  <a href="http://www.hatfulofhollow.com/posts/code/farewell-to-orms.html">Aldo</a>; ORMs increasingly get in the way.</p>
<p>Collection mapping is one of those &#8220;hello world&#8221; problems. (The &#8220;hello world&#8221; example in the doco looks totally trivial and completely ideal [which is the problem], but suck-in-the-galaxy-greet-it-and-then-map-all-the-stars problem, which is more like what your real app looks like, is far less than trivial and not so easily achieved with the demonstrated toolkit). In my experience, collection mapping is the cause of all sorts of pain and performance perfidy.</p>
<p>Here&#8217;s a further situation where I find that they <em>really</em> get in the way. Consider integration with existing systems that use highly-normalised database schemas (designed by advanced SQL programmers who know what they are doing in that language).</p>
<p>This is not an uncommon scenario &#8211; we have this system &#8216;A&#8217; which (let&#8217;s say) has all our customer shipping, product, warehousing data in it. We don&#8217;t want to replace it. But we need to extend it so that e.g. available to web systems. Or maybe it needs to be integrated into the big fancy off-the-shelf CRM we&#8217;re installing. Something like that. We need to build some sort of service layer around this system &#8216;A&#8217; so that other systems can access its data and/or functions. It&#8217;s common to think that an ORM around that big complex database schema is going to help, but in my experience, it doesn&#8217;t for many of the reasons Stephan and Aldo list. That sort of highly-normal database schema in my experiences completely kills ORM object representations stone cold. You end up with so many LazyInitialisationExceptions and various other problems it sucks productivity out the developers and performance out of the system.</p>
<p>Also, I get a bit annoyed about ORM abstractions leaking into the web tier, this is especially prevalent with using annotations rather than ORM mapping files.</p>
<p>Different sorts of approaches are sometimes needed to be applied with careful thought in that scenario. Perhaps you need to model the &#8220;intermediate&#8221; domain you need directly, and then use, for example, simple DAO layers which operate directly on the domain you&#8217;ve defined. These DAO layers then might call functions (stored procs) in the database that do the problematic mapping in an efficent relational language (after all it&#8217;s the direct representation of the target data format).</p>
<p>I&#8217;m not saying that you have to do the above in every case, or that an ORM is always wrong, but anyway the point is, ORM isn&#8217;t a magic bullet like any other technology you have to consider carefully. Your application doesn&#8217;t always need one by default.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2009/10/19/orm-is-dead-meme/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>&#8216;Disappeared&#8217; DAO layers</title>
		<link>http://www.crazymcphee.net/x/2009/02/06/disappeared-dao-layers/</link>
		<comments>http://www.crazymcphee.net/x/2009/02/06/disappeared-dao-layers/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 07:01:18 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[infrastructure and frameworks]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[test driven design]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=139</guid>
		<description><![CDATA[Adam Bien still wants to believe that a JPA layer can directly replace a formal &#8216;DAO layer&#8217;. And I still disagree. I might agree that for simple enough systems, it could end up being that in fact the service layers end up with PersistenceManager logic directly in their methods. But then I might say a [...]]]></description>
			<content:encoded><![CDATA[<p>Adam Bien still wants to believe that a <a href="http://www.adam-bien.com/roller/abien/entry/daos_aren_t_dead_but" target="_blank">JPA layer can directly replace a formal &#8216;DAO layer&#8217;</a>. And I still disagree.</p>
<p>I might agree that for simple enough systems, it could end up being that in fact the service layers end up with PersistenceManager logic directly in their methods. But then I might say a language and framework like Ruby on Rails could suit your application better in that case. For any sufficiently complex Java-based enterprise system, a POJO-style data persistence layer naturally evolves, in order to reduce as far as possible the responsibilities the service layer must carry out.</p>
<p>As mentioned by commentators on his blog, the discipline of test-driven design is usually  a strong driver of having a separated set of components that deal with persistence and other data concerns. Not just from the issue over mocking the PersistenceManager, which is certainly a strong driver, but also from design principles.</p>
<p>Service layers marshall requests from clients, and decompose them to call various component layers. Data access layers typically form part of these component layers. A TDD discipline means these data access layers usually end up with more than just CRUD operations.</p>
<p>Furthermore, as a matter of discipline, in any sufficiently complex service layer I prefer not to work directly with database abstractions (i.e. entities that are modelled on database tables and their relationships) but on first-class objects designed to fit directly with the modelled domain. I want those objects to have rich behaviour &#8211; the service layer is actually part of their behaviour. I want to start the design of the system by directly modelling those actions, e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">passenger.<span style="color: #006633;">at</span><span style="color: #009900;">&#40;</span>origin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
passenger.<span style="color: #006633;">orderJourney</span><span style="color: #009900;">&#40;</span>dispatch, destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Vehicle vehicle <span style="color: #339933;">=</span> dispatch.<span style="color: #006633;">sendVehicle</span><span style="color: #009900;">&#40;</span>origin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
vehicle.<span style="color: #006633;">pickUp</span><span style="color: #009900;">&#40;</span>passenger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
vehicle.<span style="color: #006633;">arrives</span><span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">dropsOff</span><span style="color: #009900;">&#40;</span>passenger<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
vehicle.<span style="color: #006633;">notify</span><span style="color: #009900;">&#40;</span>dispatch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I do not want these objects to know about database semantics. That is a responsibility of a separated persistence layer, which we may for convienience sake, called the DAO. Even if internally we end up with;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Passenger <span style="color: #009900;">&#123;</span>
  at<span style="color: #009900;">&#40;</span>Location origin<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">origin</span><span style="color: #339933;">=</span>origin<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  call<span style="color: #009900;">&#40;</span>DispatchCentre dispatch, Location destination<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    dispatch.<span style="color: #006633;">passengerOrder</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>DispatchCentre at this level, is a service, but we will model it as part of the domain of passengers, locations, and vehicles. Behind that service, it will have a database layer with the semantics as to how it saves and loads the data concerning passengers, locations, and vehicles. I don&#8217;t necessarily want the client objects (e.g. the web action) to have to deal with JPA annotated objects. They just deal with objects as much as possible. And I don&#8217;t see there&#8217;s anything served with developing possibly complex persistence logic directly in the DispatchCentre. In fact, taking a top-down approach, I know pretty much I won&#8217;t do that.</p>
<p>Only after I&#8217;ve done this initial part of the modelling, will I be concerned as to which of these components can be directly JPA or Hibernate annotated, which are Spring-injected services, which are Session EJBs, and the like. I think starting your modelling from the point of view of having a persistence framework like JPA or Session EJBs or any other &#8216;archtectural artifact&#8217; leads to an unnatural design.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2009/02/06/disappeared-dao-layers/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Does JPA kill the DAO Pattern?</title>
		<link>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/</link>
		<comments>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 12:30:41 +0000</pubDate>
		<dc:creator>Scot Mcphee</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[persistence]]></category>

		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=44</guid>
		<description><![CDATA[Oliver Gierke definitely thinks not. And I concur with him. A couple of years ago I got into an running battle with a developer at my old workplace as to whether the JPA architecture abstracted away enough of the persistence to justify eliminating the database layer. My answer was, and still is, certainly not! The [...]]]></description>
			<content:encoded><![CDATA[<p>Oliver Gierke <a href="http://www.olivergierke.de/wordpress/2009/01/se-radio-episode-121-or-mappers/">definitely thinks not</a>. And I concur with him.</p>
<p>A couple of years ago I got into an running battle with a developer at my old workplace as to whether the JPA architecture abstracted away enough of the persistence to justify eliminating the database layer. My answer was, and still is, <em>certainly not!</em></p>
<p>The simple answer to this question is another question &#8211; <em>What if you wanted to replace JPA?</em> The users of the data layer, lets call these objects the SessionLayer, need not, and should not know what sort of persistence layer you&#8217;re using. JPA does manage to abstract away some annoyances with choosing a specific transactional persistence technology just as Hibernate or Toplink. But what if you need to replace database access with a call to a web service? Convert the entire application to use Spring transactions? Send a non-transactional JMS message? Or just write the data in a <em>flat file</em>? </p>
<p>If you have an entirely separate data access layer, which encapsulates your data persistence methods from its users, there&#8217;s only one place to change. It&#8217;s clients need not ever know you made that change. You have <em>isolated the responsibility</em>. JPA, unencapsulated, encourages users of the data layer to consider the method of persistence. Use JPA underneath your data layer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
