Sep 20

I”ve started looking at NHibernate and I must say that I”m impressed with several of its features. However, I”ve reached a point where something isn”t quite right. I”m not sure if it”s me (which is probably the case) or if it”s a limitation/bug of NHibernate. Since I”m really a beginner, I thought I should write a quick post that explains what”s going on. Maybe someone that reads this might help me :,,).

It”s really a simple scenario: there”s an entity which has a collection of components and I expected that calling the Save method over an instance of that entity would also be cascaded to the components maintained by that object.

Instead of describing everything here, I”ll just point to a post I”ve written in the NHibernate forums (it has all the info on what”s happening). If anyone is interested in having a go, then please download the code I”ve attached to this bug entry (it has the necessary SQL to create the tables so getting a repro environment should really be easy).

3 comments so far

  1. daniel
    6:09 pm - 9-20-2007

    Hi ,
    I”m not a Nhibernate jedi, but in order to save the object you should commit the transaction or flush the session.
    calling is like telling nhibernate : persist the data when you think is right . flushing the session (or committing the transaction) forces Nhibernate to persist. p.s. transaction.rollback in the middle is making a big mess there…

  2. daniel
    6:14 pm - 9-20-2007

    p.p.s an automatic way to create the database schema via code is :
    Configuration cfg = new Configuration();

    NHibernate.Tool.hbm2ddl.SchemaExport se = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);

  3. luisabreu
    6:28 pm - 9-20-2007

    Hello Daniel.

    Yes, i know what you”re saying…however, do notice that even though the code might not make lots of sense, but it still doesn”t explain how the cascading isn”t being performed on the inner component collection as it should. in fact, that”s why i get the inner collection elements persisted even though the mian element isn”t.