Oren Eini

CEO of RavenDB

a NoSQL Open Source Document Database

Get in touch with me:

oren@ravendb.net +972 52-548-6969

Posts: 7,640
|
Comments: 51,260
Privacy Policy · Terms
filter by tags archive
time to read 1 min | 124 words

There is a new build of NQA out, this time it works against (and only against, sorry) NHibernate 1.2 Beta 2.

This time I also added support for Active Record. All you need to do is add the Active Record assembly to your project, add the app.config, and you are set. The only requirement is that the Active Record configuration section will be named "activerecord".

Now you should be able to execute queries against your objects directly. This release is marked as beta, since I have not yet been able to give it the testing that it needs. Let me know how it goes.

You can get the bits here.

time to read 1 min | 177 words

I recently had several discussions about the usage of Castle / NHibernate in projects. The argument almost always revolve around the following issues, which both sides agree on:

  • It can take time to start start developing with Castle/NHibernate. To learn the libraries, to learn the things you should not do, etc.
  • After you learn to use the libraries, the cost of change goes down, usually radically.
  • It takes some time for a new developer to be productive*.

What do you think of this issue?

* I had three new developers trickle into my team and start working with an application that I wrote using NHibernate. I won't say that they now understand the full application stack, but they were productive after about a week, and most of the time was understanding the domain, not NHibernate.

time to read 15 min | 2810 words

There are some things that you simply can't do effectively with an abstraction. Take Hierarchical Queries as a good example. They are very hard in SQL, there is no good way to solve the issue in a portable way. Therefor, each database has its own method to handle this issue. In SQL 2000, you would build a table valued function that you would query, in Oracle, you use CONNECT BY, and in SQL 2005 and DB2 (that I know of) you can use Common Table Expressions.

Out of the box, NHibernate can't handle this, but is exposes the hooks to allow this. A classic example is bringing all the messages in a thread in a single query. This is an issue since if you try to handle this by default, you'll get a query per each level in the hierarchy. Here is a simple message class, which has a parent message.

(Image from clipboard).png

And here is how we get all the messages in the hierarchy, for the message with id 43:

SimpleQuery<Message> msgs = new SimpleQuery<Message>(QueryLanguage.Sql, @"

WITH    AllMsgs ( id )

      AS ( SELECT   messages.id               FROM     Messages

           WHERE    messages.id = ?

           UNION ALL

           SELECT   messages.id               FROM     Messages

           INNER JOIN AllMsgs parent

           ON       messages.parent = parent.id )

 SELECT {msg.*}

 FROM   Messages msg

 WHERE  msg.id IN ( SELECT  id                 FROM    AllMsgs )  

", 43);

 

msgs.AddSqlReturnDefinition(typeof(Message),"msg");

Message[] messages = msgs.Execute();

The SQL query is standard SQL for SQL Server 2005, with two slight modifications. The ? marks a positional parameter, in this case, the 43 that we pass to the query. And the {msg.*}, which NHibernate will expand for you to the appropriate columns. It is important to notice that we need to tell the query the mapping between the Message type and the "msg" alias.

We brought all the message hierarchy to the application in one shot, instead of N+1. This is really good, if you are interested only in the properties of the message. A slight complication may arise if you want to handle the author for each message. Now we need to bring not only use the messages, but their authors, preferably in a single query. Let us see how we tackle this.

We will want to pull everything in one go, which means that we need to join between the messages and users table. This, in turn, means that we will get a list of tuples back. Here is the query itself:

SimpleQuery<object[]> msgs = new SimpleQuery<object[]>(typeof(Message),QueryLanguage.Sql, @"

WITH    AllMsgs ( id )

      AS ( SELECT   messages.id               FROM     Messages

           WHERE    messages.id = ?

           UNION ALL

           SELECT   messages.id               FROM     Messages

           INNER JOIN AllMsgs parent

           ON       messages.parent = parent.id )

 SELECT {msg.*}, {u.*}

 FROM   Messages msg JOIN Users u on msg.Author = u.id

 WHERE  msg.id IN ( SELECT  id                 FROM    AllMsgs )

", 43);

 

msgs.AddSqlReturnDefinition(typeof(Message),"msg");

msgs.AddSqlReturnDefinition(typeof(User), "u");

 

object[][] messages_and_users = msgs.Execute();

Here is how you use this now:

foreach (object[] message_and_user in messages_and_users)

{

       Message message = (Message) message_and_user[0];

       Console.WriteLine("{0} - {1}", message.Author.Name, message.Id);

}

Notice that even though we brought the user from the database, we don't access it from the tuple, we access it normally, from the message object. NHibernate is smart enough to figure out that it already loaded it, and can use it directly.

A note, NHibernate itself can use the mapping file to hide all of this from you, which you can later modify without touching the code (or even recompiling). Active Record has no such facility that I know of, though.

This post is dedicated to the localhost blogger.

time to read 2 min | 284 words

So two days ago there was the Israeli Blogger dinner, it was a blast. 16 bloggers and a single localhost blogger showed up, which was more than I thought there were, as a matter of fact.

Highlights of the evening:

  • Getting to tell jokes about the value of Heaps Of Meat vs. Stacks of Meat.
  • Waiting for the meat.
  • Trying to participate in three very interesting conversation at once.
  • Hearing quite a lot about the community in Israel and abroad.

I am definately going to be at the next one, and it should defianately be a regular occurance. You can get some pictures here (look for the goofy looking fellow, that is me).

The dinner itself was great, but the end was soured by the place - Papagaio Azrieli - trying to scam us. I wouldn't have anything good to say on the service, cost or the quality of food, but the last part was over the top (charging for drinks that we thought were supposed to be part of the meal).

Next time, we are going to do it some place else (still a meat-joint, fear not), and it is definately going to need bigger tables, I think that I missed about 50% of the interesting talk because I was too far away.

Chears for Omer for organizing it.

time to read 3 min | 448 words

Book Review: In Search Of Stupidity, 2nd Edition
Note: I got a free copy of the book.


In Search of Stupidity: Over Twenty Years of High Tech Marketing Disasters, Second Edition

I don't generally read the 2nd edition of books that I have already read, and I have read (and enjoyed) the first version of this book very much. I have pretty good memory and very low tolerance for boredom.

I was very pleased to se that there are a lot of new stuff in the book, and that the stuf that I have read already is still extremely entertaining. I just went back and read my first review of this book, and I still stand behind every word there. It is an hilarious book, and probably something that should be mandatory reading for a lot of people in the tech world.

A lot of the stuff that I read are stuff that I can personally relate to. (Throwing out a working printers database and starting from scratch sound a lot like running after the latest tech in a lot of customers that I see.)

The comment I made previously about errors the author has done still stand, and it still bothers me. And there are several instances where I felt that the author ignores other factors that are relevant to the issue at hand. A good example of this is that the positioning conflict between Windows 9x and Windows NT. There are a lot of technical / business reasons for this, which affected the decision, which the author simply ignored. That was not mal-practice that brought this, it was the very valid issues that brought this decision.

The new stuff from the first version seems to be case analsys that explains what he thinks would have been a good solutions to the stupid ations done. And some new (and recent) perspectives. His treatment of the Google's issues with "Do No Evil (for anyone with less than a billion)" was really good, for instance. And I fully agree with the stupidity of having 6 versions of Windows Vista.

You really should read this book, as an amusing passtime at the very least. It is comedy, history and warning combined into one book. At the very least, you can now (hopefully) say: "This hasn't work for XYZ when they tried it...", etc.

Highly recommended reading.

BooksFun | Books
time to read 1 min | 102 words

I was asked to help an application that was suffering un-optimal performance with NHibernate today. The first thing that I did was upgrade the application to NHibernate 1.2 (which took some time, damn non-virtual methods).

After I was done, I run the application, and was basically done. Just by upgrading to 1.2, we saw a major performance improvement. Now, to be fair, this is not just because NHibernate 1.2 is so much better (although it is :-) ). It is that it has different defaults (specifically about lazy loading) that make a huge difference in performance.

time to read 1 min | 108 words

Did you get a hard to understand error from NHibernate and didn't know quite what to do?

I am planning on going over NHibernate's error messages and see if I can improve the amount of information that they give you, but I would like to hear from you what the most annoying error messages are, and attempt to improve them (or at least explain why they are that way.

Please note that I am only talking about errors that are hard to understand when you view the entire exception stack. Not reading the inner exception is not excuse.

time to read 1 min | 76 words

Well, here is the first of the goodies.

I have updated NQA to work against NHibernate 1.0.3, so anyone who upgraded can still use it. Please note that this is avialable for .Net 2.0 only.

The binaries are here, but the sources are not in the usual place, instead they are in the NHibernate 1.0.x branch here.

Have fun.

Geek Motivation

time to read 1 min | 103 words

There are a lot of stuff that I have been intending to do for quite some time. This mostly includes various releases for updates and fixes in the OSS projects that I work on.

I'm going to work on that today. But I said that before about 5/6 times. This time it is going to be different. This time, I have a prize at the end. I got Vista RTM just waiting to be installed. When I finish everything, it is time to hit the big blue button and see what would happen to my PC...

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. API Design (10):
    29 Jan 2026 - Don't try to guess
  2. Recording (20):
    05 Dec 2025 - Build AI that understands your business
  3. Webinar (8):
    16 Sep 2025 - Building AI Agents in RavenDB
  4. RavenDB 7.1 (7):
    11 Jul 2025 - The Gen AI release
  5. Production postmorterm (2):
    11 Jun 2025 - The rookie server's untimely promotion
View all series

Syndication

Main feed ... ...
Comments feed   ... ...