Any NHibernate experts out there?

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).

Advertisements

~ by Luis Abreu on September 20, 2007.

3 Responses to “Any NHibernate experts out there?”

  1. Hi ,
    I”m not a Nhibernate jedi, but in order to save the object you should commit the transaction or flush the session.
    calling session.save 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. p.p.s an automatic way to create the database schema via code is :
    Configuration cfg = new Configuration();
    cfg.Configure(DB_PATH);

    NHibernate.Tool.hbm2ddl.SchemaExport se = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
    se.Create(false,true);

  3. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: