<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Does JPA kill the DAO Pattern?</title>
	<atom:link href="http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/</link>
	<description>programming idiom and methodology</description>
	<lastBuildDate>Tue, 13 Jul 2010 23:23:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Scot Mcphee</title>
		<link>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/comment-page-1/#comment-9</link>
		<dc:creator>Scot Mcphee</dc:creator>
		<pubDate>Fri, 16 Jan 2009 21:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=44#comment-9</guid>
		<description>I certainly take that as far it is. I personally have been in the situation where you&#039;re replacing database access with service calls, in that case because we were reading some critical data straight out of a database that didn&#039;t &quot;belong&quot; to the development group I was part of. We did that for speed in early iterations. Come phase 2, and we were told to replace the direct database access with calls to the &quot;proper&quot; service layer. The rationale being that the database we were reading out of was part of a system about to be made obsolete &quot;in the near future&quot; (for some value of &quot;near&quot;) and the &quot;switch&quot; would be made under the service layer.

However if you consider a simple design -  and here let&#039;s say some sort of services layer over a database - I think it&#039;s a really fatal mistake to pollute the services layer with of JPA or Hibernate (etc) query constructions and manipulations. The service layer&#039;s job is to marshal the service input, ask the &lt;em&gt;data layer&lt;/em&gt; to do it&#039;s work, and marshal the result back to the requestor. In my view it&#039;s &lt;em&gt;never&lt;/em&gt; bad form to do something like this;

&lt;pre lang=&quot;java&quot;&gt;
public class ServiceLayer implements Service {
    public DataOut myService(DataIn in) {
        // unmarshal and check DataIn if neccessary
        someData someData = someDataLayer
         .findSomeDataUsingAStoredProcedureAlreadyInTheDB(in.getName());
        MoreData moreData = moreDataLayer
         .createMoreDataRelationshipUsingAFancyHSQLQueryOperations(in, someData);
        return new DataOut(someData, moreData);
    }
}
&lt;/pre&gt;

For a start, as a design, that communicates effective intention. At this level of abstraction, it isn&#039;t really material exactly what the two data layer methods do. And when you do need to know what either methods do, you&#039;re not forced to consider the service layer at the same time.

Obviously, I chose method names there to reflect what might be happening &quot;under the hood&quot; of the data layer. Which isn&#039;t something you&#039;d actually do in practice. But the end result is, you&#039;ve encapsulated the access in sensibly named methods in a convenient abstraction. I don&#039;t see the problem.</description>
		<content:encoded><![CDATA[<p>I certainly take that as far it is. I personally have been in the situation where you&#8217;re replacing database access with service calls, in that case because we were reading some critical data straight out of a database that didn&#8217;t &#8220;belong&#8221; to the development group I was part of. We did that for speed in early iterations. Come phase 2, and we were told to replace the direct database access with calls to the &#8220;proper&#8221; service layer. The rationale being that the database we were reading out of was part of a system about to be made obsolete &#8220;in the near future&#8221; (for some value of &#8220;near&#8221;) and the &#8220;switch&#8221; would be made under the service layer.</p>
<p>However if you consider a simple design &#8211;  and here let&#8217;s say some sort of services layer over a database &#8211; I think it&#8217;s a really fatal mistake to pollute the services layer with of JPA or Hibernate (etc) query constructions and manipulations. The service layer&#8217;s job is to marshal the service input, ask the <em>data layer</em> to do it&#8217;s work, and marshal the result back to the requestor. In my view it&#8217;s <em>never</em> bad form to do something like this;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ServiceLayer <span style="color: #000000; font-weight: bold;">implements</span> Service <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> DataOut myService<span style="color: #009900;">&#40;</span>DataIn in<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// unmarshal and check DataIn if neccessary</span>
        someData someData <span style="color: #339933;">=</span> someDataLayer
         .<span style="color: #006633;">findSomeDataUsingAStoredProcedureAlreadyInTheDB</span><span style="color: #009900;">&#40;</span>in.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        MoreData moreData <span style="color: #339933;">=</span> moreDataLayer
         .<span style="color: #006633;">createMoreDataRelationshipUsingAFancyHSQLQueryOperations</span><span style="color: #009900;">&#40;</span>in, someData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> DataOut<span style="color: #009900;">&#40;</span>someData, moreData<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>For a start, as a design, that communicates effective intention. At this level of abstraction, it isn&#8217;t really material exactly what the two data layer methods do. And when you do need to know what either methods do, you&#8217;re not forced to consider the service layer at the same time.</p>
<p>Obviously, I chose method names there to reflect what might be happening &#8220;under the hood&#8221; of the data layer. Which isn&#8217;t something you&#8217;d actually do in practice. But the end result is, you&#8217;ve encapsulated the access in sensibly named methods in a convenient abstraction. I don&#8217;t see the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gavin</title>
		<link>http://www.crazymcphee.net/x/2009/01/16/does-jpa-kill-the-dao-pattern/comment-page-1/#comment-8</link>
		<dc:creator>Gavin</dc:creator>
		<pubDate>Fri, 16 Jan 2009 13:31:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.crazymcphee.net/x/?p=44#comment-8</guid>
		<description>Hrm, it would be nice if that were true, but in practice, I very much doubt that a simple DAO interface is sufficient to really abstract the very different data access patterns you are using with JPA and calling a web service. Seriously ... they&#039;re just not the same thing at all...

Plus, so far, I have never seen anyone actually try to do this (i.e. replace database access with something else) across their whole application. Everybody *talks* about doing it, but it (almost) never actually seems to happen in practice. So YAGNI applies.</description>
		<content:encoded><![CDATA[<p>Hrm, it would be nice if that were true, but in practice, I very much doubt that a simple DAO interface is sufficient to really abstract the very different data access patterns you are using with JPA and calling a web service. Seriously &#8230; they&#8217;re just not the same thing at all&#8230;</p>
<p>Plus, so far, I have never seen anyone actually try to do this (i.e. replace database access with something else) across their whole application. Everybody *talks* about doing it, but it (almost) never actually seems to happen in practice. So YAGNI applies.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
