Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,128 | Comments: 45,550

filter by tags archive

NHibernate 2.0 Alpha is out!

time to read 9 min | 1710 words


It gives me great pleasure to announce that NHiberante 2.0 Alpha 1 was released last night and can be downloaded from this location.

We call this alpha, but many of us are using this in production, so we are really certain in its stability. The reason that this is an alpha is that we have made a lot of changes in the last nine months (since the last release), and we want to get more real world experience before we ship this. Recent estimates are of about 100,000 lines of code has changed since the last release.

You can see the unofficial change list below. Please note that there are breaking changes in the move to NHibernate 2.0. There are also significant improvement in many fields, as you will see in a moment.

We are particularly interested in hearing about compatibility issues, performance issues and "why doesn't this drat work?" issues.

We offer support for moving to NHibernate 2.0 Alpha on the NHibernate mailing list at: nhusers@googlegroups.com (http://groups.google.com/group/nhusers).

And now, for the changes:

  • New features:
    • Add join mapping element to map one class to several tables
    • <union> tables and <union-subclass> inheritance strategy
    • HQL functions 'current_timestamp', 'str' and 'locate' for PostgreSQL dialect
    • VetoInterceptor - Cancel Calls to Delete, Update, Insert via the IInterceptor Interface
    • Using constants in select clause of HQL
    • Added [ Table per subclass, using a discriminator ] Support to Nhibernate
    • Added support for paging in sub queries.
    • Auto discovery of types in custom SQL queries
    • Added OnPreLoad & OnPostLoad Lifecycle Events
    • Added ThreadStaticSessionContext
    • Added <on-delete> tag to <key>
    • Added foreign-key="none" since the Parent have not-found="ignore". (not relevant to SQL Server)
    • Added DetachedQuery
    • ExecuteUpdate support for native SQL queries
    • From Hibernate:
      • Ported Actions, Events and Listeners
      • Ported StatelessSession
      • Ported CacheMode
      • Ported Statistics
      • Ported QueryPlan
      • Ported ResultSetWrapper
      • Ported  Structured/Unstructured cache
      • Ported SchemaUpdate
      • Ported Hibernate.UserTypes
      • Ported Hibernate.Mapping
      • Ported Hibernate.Type
      • Ported EntityKey
      • Ported CollectionKey
      • Ported TypedValue
      • Ported SQLExceptionConverter
      • Ported Session Context
      • Ported CascadingAction
  • Breaking changes:
    • Changed NHibernate.Expression namespace to NHibernate.Criterion
    • Changed NHiberante.Property namespace to NHiberante.Properties
    • No AutoFlush outside a transaction - Database transactions are never optional, all communication with a database has to occur inside a transaction, no matter if you read or write data.
    • <nhibernate> section is ignored, using <hibernate-configuration> section (note that they have different XML formats)
    • Configuration values are no longer prefixed by "hibernate.", if before you would specify "hibernate.dialect", now you specify just "dialect"
    • IInterceptor changed to match the Hibernate 3.2 Interceptor - interface changed
    • Will perform validation on all named queries at initialization time, and throw if any is not valid.
    • NHibernate will return long for count(*) queries on SQL Server
    • SaveOrUpdateCopy return a new instance of the entity without change the original.
    • INamingStrategy interface changed
    • NHibernate.Search - Moved Index/Store attributes to the Attributes namespace
    • Changes to IType, IEntityPersister, IVersionType - of interest only to people who did crazy stuff with NHibernate.
    • <formula> must contain parenthesis when needed
    • IBatcher interface change
  • Fixed bugs:
    • Fixing bug with HQL queries on map with formula.
    • Fixed exception when the <idbag> has a <composite-element> inside; inside which, has a <many-to-one>
    • Multi criteria doesn't support paging on dialects that doesn't support limiting the query size using SQL.
    • Fixed an issue with limit string in MsSql2005 dialect sorting incorrectly on machines with multiple processors
    • Fixed an issue with getting NullReferenceException when using SimpleSubqueryExpression within another subexpression
    • Fixed Null Reference Exception when deleting a <list> that has holes in it.
    • Fixed duplicate column name on complex joins of similar tables
    • Fixed MultiQuery force to use parameter in all queries
    • Fixed concat function fails when a parameter contains a comma, and using MaxResults
    • Fixed failure with Formula when using the paging on MSSQL 2005 dialect
    • Fixed PersistentEnumType incorrectly assumes enum types have zero-value defined
    • Fixed SetMaxResults() returns one less row when SetFirstResult() is not used
    • Fixed Bug in GetLimitString for SQL Server 2005 when ordering by aggregates
    • Fixed SessionImpl.EnableFilter returns wrong filter if already enabled
    • Fixed Generated Id does not work for MySQL
    • Fixed one-to-one can never be lazy
    • Fixed FOR UPDATE statements not generated for pessimistic locking
  • Improvements:
    • Added Guid support for Postgre Dialect
    • Added support for comments in queries
    • Added Merge and Persist to ISession
    • Support IFF for SQL Server
    • IdBag now work with Identity columns
    • Multi Criteria now uses the Result Transformer
    • Handling key-many-to-one && not-found
    • Can now specify that a class is abstract in the mapping.
  • Guidance:
    • Prefer to use the Restrictions instead of the Expression class for defining Criteria queries.
  • Child projects:
    • Added NHibernate.Validator
    • Added NHibernate.Shards
    • NHibernate.Search updated match to Hibernate Search 3.0
  • Criteria API:
    • Allow Inspection, Traversal, Cloning and Transformation for ICriteria and DetachedCriteria
      • Introduced CriteriaTransformer class
      • GetCriteriaByPath, GetCriteriaByAlias
    • Added DetachedCriteria.For<T>
    • Added Multi Criteria
    • Projections can now pass parameters to the generated SQL statement.
    • Added support for calling Sql Functions (HQL concept) from projections (Criteria).
    • Added ConstantProjection
    • Added CastProjection
    • Can use IProjection as a parameter to ICriterion
  • Better validation for proxies:
    • Now supports checking for internal fields as well
    • Updated Castle.DynamicProxy2.dll to have better support for .NET 2.0 SP1
  • SQL Lite:
    • Support for multi query and multi criteria
    • Supporting subselects and limits
    • Allowed DROP TABLE IF EXISTS semantics
  • PostgreSQL (Npgsql):
    • Enable Multi Query support for PostgreSQL
  • FireBird:
    • Much better overall support
  • Batching:
    • Changed logging to make it clearer that all commands are send to the database in a single batch.
    • AbstractBatcher now use the Interceptor to allow the user intercept and change an SQL before it's preparation
  • Error handling:
    • Better error message on exception in getting values in Int32Type
    • Better error message when using a subquery that contains a reference to non existing property
    • Throws a more meaningful exception when calling UniqueResult<T>() with a value type and the query returns null.
    • Overall better error handling
    • Better debug logs
  • Refactoring:
    • Major refactoring internally to use generic collections instead of the non generic types.
    • Major refactoring to the configuration and the parsing of hbm files.
  • Factories:
    • Added ProxyFactoryFactory
    • Added BatchingBatcherFactory


julian jelfs

This is great news. As a slight aside, do you happen to know how much of this new functionality is included in the NHibernate In Action book? Just wandering whether it is still a good book to buy or whether it would be better to hang out for something that covers the version 2 functionality.


Can you explain a little more on this:


Prefer to use the Restrictions instead of the Expression class for defining Criteria queries.

Why is Restrictions preferred and why we should switch to it ? Is Expression only included for backward compatibility ? Will it be depreciated at some point in the future ?


Ayende Rahien


To the best of my knowledge, no. But I am not sure about that

Ayende Rahien

Restrictions is the Hibernate term.

Expression is there and still works, but the documentation will refer to Restrictions.

Jon Skeet

Where does LINQ to NHibernate fit into NHibernate 2.0, out of interest? I haven't kept track of whether it's now part of the NHibernate release, or whether it's separate. Any comments on the current state of play and the potential future position?

Ayende Rahien

Linq for NHibernate is handled as a separate project at the moment, until we get enough critical mass behind it to roll it into NHibernate.

Help is always appreciated.

Jon Skeet

I would really, really love to get involved - but there are a few things stopping me at the moment in terms of time and some professional contract concerns. However, those may resolve themselves in the next month or so - I'll keep bearing it in mind :)

Ayende Rahien

Consider this as an open invitation, then :-)

Tobin Harris


I'm helping out on the "NHibernate in Action" book, and I believe it would be great to see it revised to include some NHibernate 2.0 specific stuff. I'll have a chat with Kuate and Manning and post up what the plan is.

John Morales

Cool stuff, hopefully I can play with it soon. Where are you getting these fancy logo's from? :)


Has the documentation been updated to cover the 2.0 features? If so, a direct link would be helpful.

Paul Batum

I was wondering where Castle.ActiveRecord is in terms of support for this release. Can anyone give me the lowdown?

Mark Traudt

Great stuff! I do have two questions:

1) Given all of these updates, how does NHibernate compare feature-wise to the latest version of Hibernate?

2) I seem to recall there was talk of a rewrite of the HQL parser. Did this happen? If I am not mistaken, there are some limitations of the current parser that were fixed in Hibernate.

Ayende Rahien

1/ Fairly well, I would say. We have some features they don't have, and vice versa. You would have to be more specific about things.

2/ Wasn't done for this release, and yes, this is a problem in some scenarios

Ayende Rahien


It is compatible on the trunk



Does NHibernate.Linq support MultiQuery? I'm guessing no, as I don't really see how to make that happen in my repositories without a direct dependency on NHIbernate, but I figured I'd ask anyway.



Yovanny Rodr&#237;guez

Hello Ayende,

How can I with NHibernate POCOs with WCF? I have not found a comprehensive solution for this matters. Thx

Ayende Rahien

You better ask in the mailing list.

Francisco Lozano

@Yovanny Rodríguez:

I think you should keep your WCF interface contracts (XSDs, WSDLs, DataContract's and all that stuff) separated from your persistent domain (your POCOs). The WCF interface contract could be considered in fact a public application-level protocol, that shouldn't be affected by your internal domain. Trying to pretend that the network does not exist and that you can treat the data coming from the network as if it was coming from another layer in your application is a common error that makes people expose horrible application-level network protocols (WCF contracts, WSDLs and that) that change often and show too much internal details to the world.


how about the integration of the minlib framework? is it in this release?

Ayende Rahien

Since I don't know what minlib is, the answer is probably no


The new event system is really nice http://www.slickcode.net/2008/04/nhibernate-20-events-and-listeners.html

Andrew Clancy


Great news. Team has just upgraded so looking forward to good things ...

3 questions, 1 relevant but all related:

1) Does the NHibernate Query Generator work with NHibernate 2?

2) Can you use NHG interchangably with DetachedCriteria (and Criteria)?

3) Will Linq to NHibernate supercede both NHG and DetachedCriteria/Criteria?



Andrew Clancy

clarifying question 3: I assume NHG & Linq both wrap/adapt Criteria. I mean will Linq 2 NH 'cover all bases' allow a dev to query without using Criteria (and HQL for that matter).

  • Andy
Ayende Rahien

1/ Yes

2/ Yes

3/ Hopefully, we will have to see

Matthew Robinson

Thanks for your wonderful work on NHibernate. I've just been introduced to it a few weeks ago through a work colleague who was discussing domain driven design, and I'm very impressed with what I've already seen.

One thing I wanted to do was add validation to my business logic. I found that Hibernate has a Validator class which is just what I'm looking for:


To me it looks like you can just annotate the domain model within the class (or even the interface!) with the constraints, e.g. min & max text length, min & max numeric value, not null, regular expression patterns, and others. It then allows validation by listening on Hibernate's PreInsertEvent and PreUpdateEvent, and also provides ability for application level validation, and presentation layer validation.

I was very excited when I found that NHibernate includes a "Child project"called NHibernate.Validator however I can't figure out how to annotate my domain model. I've looked through the NHibernate download (I'm running a C# project with .NET 2.0). I even tried looking through the "2.0.0.Alpha1-src" but couldn't figure it out. How do I annotate my properties with the Hibernate equivalent of @Length, @Max, @Min, etc?

If it's available, that would be great because it would provide a single point to annotate data constraints, then allow the web interface to display and trap data validation errors, and do a final check with NHibernate before the insert or update.

Thanks for your time and thanks again for all your great work!


Matthew Robinson.

Ayende Rahien


Please ask in the list


There is no mention anywhere on the timescales for the 2.0 release. Can anyone enlighten us further ?

Out of interest, who decides this sort of stuff?


Comment preview

Comments have been closed on this topic.


  1. The worker pattern - about one day from now

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats