<?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: Hibernate HQL And Performance</title>
	<atom:link href="http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/</link>
	<description>Musings of a software developer in Milwaukee, WI.</description>
	<pubDate>Tue, 06 Jan 2009 09:15:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: mooritze</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-14222</link>
		<dc:creator>mooritze</dc:creator>
		<pubDate>Thu, 25 Sep 2008 03:42:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-14222</guid>
		<description>Dude,
This a completely stupid article. Don't use SQL eh?? Have you ever built a real app? I wish google didn't index your post!!!</description>
		<content:encoded><![CDATA[<p>Dude,<br />
This a completely stupid article. Don&#8217;t use SQL eh?? Have you ever built a real app? I wish google didn&#8217;t index your post!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hibernate , rich clients and long running sessions &#171; Blog</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11166</link>
		<dc:creator>Hibernate , rich clients and long running sessions &#171; Blog</dc:creator>
		<pubDate>Fri, 15 Feb 2008 03:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11166</guid>
		<description>[...] http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/" rel="nofollow">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11140</link>
		<dc:creator>Florian</dc:creator>
		<pubDate>Sun, 27 Jan 2008 12:37:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11140</guid>
		<description>Matt,

you can easily load scalar values with the criteria API, you do not need HQL for this.

Example:
You have a Company with an one-2-one relation to an Address.
You just want to query id and name of the Company and the countryCode of its related Address.

myCompanyCriteria.createAlias("address", "joinedAddress");

myCompanyCriteria.setProjection(
   Projections.projectionList()
      .add( Projections.id(), "id" )
      .add( Projections.property("name"), "name" )
      .add( Projections.property("joinedAddress.countryCode"), "countryCode" )
   );

myCompanyCriteria.setResultTransformer( new AliasToBeanResultTransformer(CompanyVO.class) );

The Class CompanyVO just needs setter for id, name and countryCode.


Regards</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>you can easily load scalar values with the criteria API, you do not need HQL for this.</p>
<p>Example:<br />
You have a Company with an one-2-one relation to an Address.<br />
You just want to query id and name of the Company and the countryCode of its related Address.</p>
<p>myCompanyCriteria.createAlias(&#8221;address&#8221;, &#8220;joinedAddress&#8221;);</p>
<p>myCompanyCriteria.setProjection(<br />
   Projections.projectionList()<br />
      .add( Projections.id(), &#8220;id&#8221; )<br />
      .add( Projections.property(&#8221;name&#8221;), &#8220;name&#8221; )<br />
      .add( Projections.property(&#8221;joinedAddress.countryCode&#8221;), &#8220;countryCode&#8221; )<br />
   );</p>
<p>myCompanyCriteria.setResultTransformer( new AliasToBeanResultTransformer(CompanyVO.class) );</p>
<p>The Class CompanyVO just needs setter for id, name and countryCode.</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11128</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Mon, 14 Jan 2008 02:03:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11128</guid>
		<description>Matt,

&#62;But what if I only need a list of names and ids? I don’t need placeholder
&#62;objects taking up space in my JVM if they’re never used.

So how can one achieve such a query which does not pull in all the properties?


Thanks,
Dan</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>&gt;But what if I only need a list of names and ids? I don’t need placeholder<br />
&gt;objects taking up space in my JVM if they’re never used.</p>
<p>So how can one achieve such a query which does not pull in all the properties?</p>
<p>Thanks,<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Ketteridge</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11119</link>
		<dc:creator>Ben Ketteridge</dc:creator>
		<pubDate>Tue, 08 Jan 2008 15:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11119</guid>
		<description>I'd have to agree with the HIbernate Docs on fetch strategies -- if you specify the fetch strategy in the domain mapping (whether by annotation or the xml), then you're committing all uses of that strategy for the given relationship to use that same strategy, whether that is appropriate or not.

Eg. you have a Brokerage that contains many Brokers, when you fetch a list of Brokerages, you do not want the child relationship brokers to be eagerly fetched - it should be allowed to remain in the normal lazy mode. However, when you're fetching a specific Brokerage for display, in a context that wants to also display a table of the Brokers within the Brokerage, then you want the Brokers to be fetched eagerly (perhaps with a “from parent as p left join fetch p.dependentObject” DAO method)  as part of the Brokerage fetch to avoid an N+1 fetch scenario.

(If Brokers and Brokerages are not your bag, you can substitute Brokerage with Order, and Broker with OrderLine for the same effect)

Providing the DAO layer is the primary method for fetching objects (and you never pollute the service/UI layers with hibernate manipulations of the persisted object graph) then it is quite reasonable to have transaction specific logic - it's still only in one place, just not enforced at a POJO domain object level, where there is no knowledge of the transactional context of an operation.</description>
		<content:encoded><![CDATA[<p>I&#8217;d have to agree with the HIbernate Docs on fetch strategies &#8212; if you specify the fetch strategy in the domain mapping (whether by annotation or the xml), then you&#8217;re committing all uses of that strategy for the given relationship to use that same strategy, whether that is appropriate or not.</p>
<p>Eg. you have a Brokerage that contains many Brokers, when you fetch a list of Brokerages, you do not want the child relationship brokers to be eagerly fetched - it should be allowed to remain in the normal lazy mode. However, when you&#8217;re fetching a specific Brokerage for display, in a context that wants to also display a table of the Brokers within the Brokerage, then you want the Brokers to be fetched eagerly (perhaps with a “from parent as p left join fetch p.dependentObject” DAO method)  as part of the Brokerage fetch to avoid an N+1 fetch scenario.</p>
<p>(If Brokers and Brokerages are not your bag, you can substitute Brokerage with Order, and Broker with OrderLine for the same effect)</p>
<p>Providing the DAO layer is the primary method for fetching objects (and you never pollute the service/UI layers with hibernate manipulations of the persisted object graph) then it is quite reasonable to have transaction specific logic - it&#8217;s still only in one place, just not enforced at a POJO domain object level, where there is no knowledge of the transactional context of an operation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Brock</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11104</link>
		<dc:creator>Matt Brock</dc:creator>
		<pubDate>Sat, 15 Dec 2007 21:39:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11104</guid>
		<description>There's virtually no performance difference between HQL and Criteria.  The principal benefit of the Criteria API is that the code is cleaner and more abstracted from the final generated SQL.  However, the more complex your queries become, the deeper you must delve into the inner workings of Hibernate--which kind-of defeats the purpose.

I find I still end up using HQL for most of my DAOs, however, because HQL can return scaler results which are far more performant than fully-hydrated objects.  Sometimes I don't need a whole domain object--I just want a couple of properties.  For instance: let's say I have a Customer class that has dozens of simple properties (id, name, account number, etc.), as well as a bunch of associated collections (Addresses, Bank Accounts, Transactions, etc.).  If I do a criteria query on the Customer.class, I'll get a bunch of Customer objects back with all the simple (non-lazy) properties, and PersistentCollection placeholders for my (lazy-loaded) collections.

But what if I only need a list of names and ids?  I don't need placeholder objects taking up space in my JVM if they're never used.  A good example of this is drop-down auto-complete forms: you type something in, a list of partially matched Customers comes back.  You're not interested in the Customer's addresses, or their lastModified date, or any of that stuff.  You really just want an array of strings.

&#62; But that knowledge is already represented in your mapping file, so this
&#62; is repeating that knowledge in many places

The Hibernate docs actually recommend *against* specifying fetching strategies in the mappings. From the docs (19.1.2. - Tuning fetch strategies): "Usually, we don't use the mapping document to customize fetching. Instead, we keep the default behavior, and override it for a particular transaction..."</description>
		<content:encoded><![CDATA[<p>There&#8217;s virtually no performance difference between HQL and Criteria.  The principal benefit of the Criteria API is that the code is cleaner and more abstracted from the final generated SQL.  However, the more complex your queries become, the deeper you must delve into the inner workings of Hibernate&#8211;which kind-of defeats the purpose.</p>
<p>I find I still end up using HQL for most of my DAOs, however, because HQL can return scaler results which are far more performant than fully-hydrated objects.  Sometimes I don&#8217;t need a whole domain object&#8211;I just want a couple of properties.  For instance: let&#8217;s say I have a Customer class that has dozens of simple properties (id, name, account number, etc.), as well as a bunch of associated collections (Addresses, Bank Accounts, Transactions, etc.).  If I do a criteria query on the Customer.class, I&#8217;ll get a bunch of Customer objects back with all the simple (non-lazy) properties, and PersistentCollection placeholders for my (lazy-loaded) collections.</p>
<p>But what if I only need a list of names and ids?  I don&#8217;t need placeholder objects taking up space in my JVM if they&#8217;re never used.  A good example of this is drop-down auto-complete forms: you type something in, a list of partially matched Customers comes back.  You&#8217;re not interested in the Customer&#8217;s addresses, or their lastModified date, or any of that stuff.  You really just want an array of strings.</p>
<p>&gt; But that knowledge is already represented in your mapping file, so this<br />
&gt; is repeating that knowledge in many places</p>
<p>The Hibernate docs actually recommend *against* specifying fetching strategies in the mappings. From the docs (19.1.2. - Tuning fetch strategies): &#8220;Usually, we don&#8217;t use the mapping document to customize fetching. Instead, we keep the default behavior, and override it for a particular transaction&#8230;&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajesh Patel</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11085</link>
		<dc:creator>Rajesh Patel</dc:creator>
		<pubDate>Fri, 30 Nov 2007 13:45:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11085</guid>
		<description>The criteria API has the same "limitations" in regard to the cache that you are pointing out with HQL.</description>
		<content:encoded><![CDATA[<p>The criteria API has the same &#8220;limitations&#8221; in regard to the cache that you are pointing out with HQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Lane</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11009</link>
		<dc:creator>Geoff Lane</dc:creator>
		<pubDate>Fri, 26 Oct 2007 16:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11009</guid>
		<description>Rob,
That's exactly what I was trying to say. Use natural relationships and criteria queries to load objects in a domain driven way. Do not do a transaction script pattern of a bunch of HQL queries buried in an application un-aware data access layer.</description>
		<content:encoded><![CDATA[<p>Rob,<br />
That&#8217;s exactly what I was trying to say. Use natural relationships and criteria queries to load objects in a domain driven way. Do not do a transaction script pattern of a bunch of HQL queries buried in an application un-aware data access layer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-11008</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Fri, 26 Oct 2007 15:32:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-11008</guid>
		<description>I've been using NHibernate HQL and Criteria in a production environment for years and when used properly Criteria is a LOT faster than HQL. I'm guessing this is not the case with Hibernate Criteria</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been using NHibernate HQL and Criteria in a production environment for years and when used properly Criteria is a LOT faster than HQL. I&#8217;m guessing this is not the case with Hibernate Criteria</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Lane</title>
		<link>http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/comment-page-1/#comment-10841</link>
		<dc:creator>Geoff Lane</dc:creator>
		<pubDate>Thu, 05 Jul 2007 15:40:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/2006/08/23/hibernate-hql-and-performance/#comment-10841</guid>
		<description>You of course can make all kinds of modifications to HQL sprinkled all over your data access layer. But that knowledge is already represented in your mapping file, so this is repeating that knowledge in many places. And it doesn't "override" the declarations in the mappings, because those declarations aren't ever used by HQL in the first place.

The main problem is when going back and running the same query that could have been expressed as an object relationship. The natural object relationships are where hibernate shines. HQL should be reserved for very special situations.</description>
		<content:encoded><![CDATA[<p>You of course can make all kinds of modifications to HQL sprinkled all over your data access layer. But that knowledge is already represented in your mapping file, so this is repeating that knowledge in many places. And it doesn&#8217;t &#8220;override&#8221; the declarations in the mappings, because those declarations aren&#8217;t ever used by HQL in the first place.</p>
<p>The main problem is when going back and running the same query that could have been expressed as an object relationship. The natural object relationships are where hibernate shines. HQL should be reserved for very special situations.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
