﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Mats Helander commented on NHibernate – not all that glitters is gold</title><description>Frans,
  
  
I absolutely agree about delaying the creation of the SQL until all the manuipulation has been done. All I'm saying is that the last possible time is probably going to be a bit before the SQL is actually used, and the earlier you can let the GC collect the AST, the better. 
  
  
Ayende,
  
  
Yup, I understand, I'm just suggesting that your last step, "finally generate the SQL" be turned into a two-stepper: First generate an SQL DOM and then use visitors to spit out the SQL string from there.
  
  
One reason for this is that it allows you to isolate many of the db differences to this last step, using different visitors to support different databases and allowing you to move complexity out of the AST-SQL transformation phase. 
  
  
Take joins for example. Your SQL DOM would only have one format for joins, meaning that the AST-SQL transformation would only have to work with one join format. Then the different visitors turn the SQL DOM joins into the correct join syntax for their respective databases.
  
  
I just think that a year from now, you may be posting "There are certainly things that I would change with NHibernate/Hibernate if I were able. One of the things on the very top of the list would be to turn the entire internals to 
****SQL DOM
 manipulation and delay the actual generation of SQL to just before executing the query / command."
  
  
/Mats
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment16</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment16</guid><pubDate>Mon, 01 Oct 2007 09:15:36 GMT</pubDate></item><item><title>Frans Bouma commented on NHibernate – not all that glitters is gold</title><description>Mats: delaying the SQL generation till the final moment allows you to add/remove/manipulate elements in the query specification elements at various levels. I do that too. For example the eager loading/prefetch path stuff manipulates the query specification objects to optimize the node queries based on the data known at that moment. If the query would have been generated early on, it would have come down to SQL string manipulation which sucks :).
  
  
Another advantage is that you can centralize the tree optimizations for all databases and simply have 'sql generators' per database. 
  
  
Steve: wanting a single query for 1:n related entities isn't always what you want: the PK side will get duplicated in the rows, and this can be potentially be a lot of times, which means that the amount of data returned is huge. 
  
  
In Objectspaces they had a trick where they used a union query which unioned the query per node to the main set and had NULL values for the fields from the entities not fetched in that node, so if you wanted Customer + Order (1:n) you had 1 select with the customer fields and NULL values for the Order fields UNION 1 select with the order fields and NULL values for the customer fields. This would be still 1 resultset but not the data explosion of the duplicate rows. 
  
  
Of course, having a multiple branched tree would give a lot of problems. 
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment15</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment15</guid><pubDate>Mon, 01 Oct 2007 08:37:15 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>I take a query (HQL, Criteira, Linq, etc) and generate an AST, process it through everything that we may need, and finally generate SQL from it.
  
That is the overall idea.
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment14</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment14</guid><pubDate>Mon, 01 Oct 2007 06:24:30 GMT</pubDate></item><item><title>Mats Helander commented on NHibernate – not all that glitters is gold</title><description>The AST is another representation of the "same thing" (the HQL string). Why do you see the need for that? /Mats
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment13</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment13</guid><pubDate>Mon, 01 Oct 2007 06:13:46 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>Okay, so you are talking about HQL AST and SQL DOM.
  
I don't really see the need to create two representations of the same thing. We could probably generate the SQL directly of the HQL AST.
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment12</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment12</guid><pubDate>Mon, 01 Oct 2007 05:26:47 GMT</pubDate></item><item><title>Mats Helander commented on NHibernate – not all that glitters is gold</title><description>I meant that first you parse the HQL, that will give you your AST (which is indeed a DOM). From there, you /could/ go right ahead and generate the resulting SQL strings directly. What I'm suggesting is that you don't do that, but instead (create the classes for and then) generate a SQL DOM from the AST. Then, finally, you generate the SQL strings from the SQL DOM - which can be done using visitors (where you can use different visitors for different databases). Makes sense? ´But perhaps NH is already doing this?
  
  
/Mats 
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment11</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment11</guid><pubDate>Sun, 30 Sep 2007 22:31:06 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>Mats,
  
I don't think that I understand the different between AST and DOM
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment10</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment10</guid><pubDate>Sun, 30 Sep 2007 21:47:06 GMT</pubDate></item><item><title>Mats Helander commented on NHibernate – not all that glitters is gold</title><description>Ok, means we agree. Could I also suggest you generate a Sql Dom instead of strings from the AST? (Again, DOM over string). 
  
  
/Mats
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment9</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment9</guid><pubDate>Sun, 30 Sep 2007 21:46:30 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>The idea is that you want to delay that as late as possible to allow transformation of the AST at all levels.
  
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment8</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment8</guid><pubDate>Sun, 30 Sep 2007 02:03:30 GMT</pubDate></item><item><title>Mats Helander commented on NHibernate – not all that glitters is gold</title><description>"One of the things on the very top of the list would be to turn the entire internals to AST manipulation and delay the actual generation of SQL to just before executing the query / command."
  
  
I certainly agree with using an AST for all manipulation [* ahem * DOM over string manipulation, right ;-)] but why wait until the last moment before turning it into its final state, the sql string? Isn't it better to do that as soon as possible to allow the GC to collect all the objects from the AST?
  
  
/Mats
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment7</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment7</guid><pubDate>Sun, 30 Sep 2007 01:12:50 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>Steve,
  
You need to configure this at the mapping level:
  
IIRC, it is something like:
  
&lt;set fetch="join"&gt;
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment6</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment6</guid><pubDate>Sun, 30 Sep 2007 00:45:24 GMT</pubDate></item><item><title>Steve commented on NHibernate – not all that glitters is gold</title><description>Let me just make a simple one:
  
  
(Let's assume no lazy load here)
  
  
you have a Company with a list of Employees.
  
  
one to many
  
  
when I turn on nhibernate sql debugging I'll see like this:
  
  
select ... from Company where ... companyid = ?
  
select ... from Employees where companyid = ?
  
  
Two calls.
  
  
Let's say I wanted one call that was a join ? 
  
  
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment5</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment5</guid><pubDate>Sun, 30 Sep 2007 00:00:28 GMT</pubDate></item><item><title>Manuel Abadia commented on NHibernate – not all that glitters is gold</title><description>Ayende,
  
  
I replied to you here:
  
  
http://www.manuelabadia.com/blog/PermaLink,guid,736ddc0b-dc70-492f-aeff-ba09ebdeb511.aspx
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment4</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment4</guid><pubDate>Sat, 29 Sep 2007 23:29:34 GMT</pubDate></item><item><title>Dario Quintana commented on NHibernate – not all that glitters is gold</title><description>Hi Ayende, 
  
I thinks to treat with paging support (and other interesting stuff) for NHibernate, uNHAddIns it's a good approach, created for Fabio Maulo.
  
http://code.google.com/p/unhaddins/
  
  
Regards
  
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment3</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment3</guid><pubDate>Sat, 29 Sep 2007 21:02:33 GMT</pubDate></item><item><title>Ayende Rahien commented on NHibernate – not all that glitters is gold</title><description>Steve,
  
There are MANY ways to do this, actually.
  
What is the scenario?
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment2</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment2</guid><pubDate>Sat, 29 Sep 2007 20:11:57 GMT</pubDate></item><item><title>Steve commented on NHibernate – not all that glitters is gold</title><description>If there was a way to group together the calls made in an object graph, it would help tremendously, it's still too chatty.
  
  
I have no idea how this can be improved, but it would help the negative perceptions of ORM's.
</description><link>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment1</link><guid>http://ayende.com/2811/nhibernate-not-all-that-glitters-is-gold#comment1</guid><pubDate>Sat, 29 Sep 2007 19:15:12 GMT</pubDate></item></channel></rss>