Try fast search NHibernate

07 May 2009

NHibernate 2.1.0 : Executable queries

I’m proud to announce NH2.1.0 is passing all tests (same of H3.3.1) for bulk actions using HQL.

Some HQL examples:

insert into Animal (description, bodyWeight, mother) select description, bodyWeight, mother from Human

insert into Pickup (id, Vin, Owner) select id, Vin, Owner from Car

insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h where h.mother.mother is not null

update Human h set h.description = 'updated' where exists (select from h.friends f where = 'Public' )

update versioned IntegerVersioned set name = :name

update Human set name.first = :correction where id = :id

update Animal a set a.mother = (from Animal where id = 1) where = 2

update Animal set description = :newDesc where description = :desc

update Animal set bodyWeight = bodyWeight + :w1 + :w2

delete SimpleEntityWithAssociation e where size(e.AssociatedEntities ) = 0 and e.Name like '%'

delete Animal where mother is not null

delete from EntityWithCrazyCompositeKey e where e.Id.Id = 1 and e.Id.OtherId = 2

To understand what that mean think about that all executable-queries are working with <subclass>, <joined-subclass>, <subclass> + <join>, <union-subclass>, various POID generators, versioned entities ad son on.

For example using the mapping of this post executing this

insert into Animal (description, bodyWeight) select h.description, h.bodyWeight from Human h where h.mother.mother is not null

the SQL is

        ( description, body_weight ) select
            human0_2_.description as col_0_0_,
            human0_2_.body_weight as col_1_0_ 
            Human human0_ 
        inner join
            Mammal human0_1_ 
                on human0_.mammal=human0_1_.animal 
        inner join
            Animal human0_2_ 
            Animal animal1_ 
            and (
                animal1_.mother_id is not null

… stock… stumb… stumb… stumb… stack… sfrfrfrfrfrfr … (the sound of “goriziana”).

kick it on


  1. I made compilation of various NHibernate guides, help topics, walktroughts, … .
    Main source is Ayende and Fabio Maulo guides and posts.
    I forgot about this blog, maybe I will update my posts with some entries from your blog.
    Regards, Tomasz M.

  2. @model
    This is Fabio's Maulo blog, i'm not sure if you realize this from your comment.

    First of all great job for Steve and you this is fantastic.
    Please put in some place that you are fabio maulo in the blog :) in addition to the ohlo that some people miss because it seems an ad. a little about, Fabio Maulo, Argentina may be fine!

  3. Execellent job Fabio, nice one!

  4. @Gustavo
    The URL of the blog is, isn't it enough?

    That's amazing, thanks!

  5. This is really amazing. Thanks a lot!

  6. @Fabio

    In the case of:
    DELETE FROM Animal a WHERE a.BodyWeight = 200

    What happens with animals already loaded in the session cache. Is this equivalent to

    select id from Animal a where a.BodyWeight = 200
    delete from Animal a where a.BodyWeight = 200
    //remove from session cache by ids

    What happens with animals already associated in a collection. Something like (zoo 1:n animal)
    Is there some internal mechanism that will synchronize the collections?

    Zoo.Animals.Count = 400
    delete from Animal a where a.BodyWeight = 200 --deletes 3 animals
    Zoo.Animals.Count = ?