tags:

views:

814

answers:

1

I have adonet.batch_size set to 10, but when I do a save on an object graph, it will save the object and all it's children in a separate database call.

I am able to see this using the NHProf tool.

-- statement #1
INSERT INTO Preferences
-- statement #2
INSERT INTO PreferencesToWidgets
-- statement #3
INSERT INTO PreferencesToWidgets
-- statement #4
INSERT INTO PreferencesToWidgets
-- statement #5
INSERT INTO PreferencesToWidgets
-- statement #6
INSERT INTO PreferencesToWidgets
-- statement #7
INSERT INTO PreferencesToWidgets
-- statement #8
INSERT INTO PreferencesToWidgets
-- statement #9
INSERT INTO PreferencesToWidgets
-- statement #10
INSERT INTO PreferencesToWidgets
-- statement #11
INSERT INTO PreferencesToWidgets
-- statement #12
INSERT INTO Users

Users is one-to-many to Preferences
Preference is many-to-one to PreferencesToWidgets

Basically, I have a user that I add a preference to, and that preference has a bunch of preference-to-widgets added to it.

I then call session.SaveOrUpdate( user ), and all the objects are inserted in separate calls, even though the batch size is set to 10.

I am doing the configuration via FluentNHibernate.

Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey( connectionStringKey ) )
.ProxyFactoryFactory( "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu" ) )
.Mappings( m => m.FluentMappings.AddFromAssembly( typeof( SessionFactoryFactory ).Assembly ) )
.ExposeConfiguration( cfg => cfg.SetProperty( "generate_statistics", "true" ) )
.ExposeConfiguration( cfg => cfg.SetProperty( "adonet.batch_size", "10" ) )
.BuildSessionFactory();
+4  A: 

I think I found the answer right after I submitted. It's because I'm using SQL Server to generate the ids for me, so the query needs to select back the id of the insert. I can actually see this in NHProf, but didn't catch it.

INSERT INTO PreferencesToWidgets
...
select SCOPE_IDENTITY()

http://stackoverflow.com/questions/1152138/nhibernate-2-1-0-4000-doesnt-seem-to-like-batch-insert

Josh Close