tags:

views:

348

answers:

4

hi there,

I create the Session factory like:

FluentConfiguration cfg =
    Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(
        c => c.Is(dbConnectionString)).**AdoNetBatchSize(100)**.ShowSql()).                    
            Mappings(m => m.FluentMappings.AddFromAssembly(mappingAssembly)).
            Mappings(m => m.HbmMappings.AddFromAssembly(mappingAssembly));

If I later set session.SetBatchSize(someOtherSize); during the later program execution nothing happens. it is as if this command is just a mock.

Why that?

Thanks in advance

A: 

How are you checking that batching actually occurs and what batch size is being used? SQL profiler does not show batching, you have to use NHibernate Profiler to get a good understanding of what is being batched.

Looking at the NH source session.SetBatchSize() does what it says it does, so it should work :)

Torkel
(sess.SessionFactory)).Settings.AdoBatchSize does not change after I apply session.SetBatchSize(someOtherSize)(debugger verified)Now at the next step the batching(whatever batchsize Im using)does not have any effect. The NHProfiler does not show anything concerning batchsize.This would be my next question.
urpcor
Well it's may be because NHProd as nothing to show. Example you have an order where you bought one Product (item). NH save the order and the item but you won't see any difference in NHProf but if you save an Order with 150 items (different), you should see a difference in NHProf
Kris-I
I see a difference in NHProg with this (+ line ine the configu file)using (ITransaction tx = _session.BeginTransaction()){ _session.SetBatchSize(50); ...... tx.Commit(); _session.SetBatchSize(3);}
Kris-I
maybe I have some screwed NH Library installation.Scraped together the Fluent, Linq toNhibernate and the NHhibernate binaries based on the NH version number.
urpcor
A: 

Don't forget to set the <property name="adonet.batch_size">3</property> in the config file. The max value, I think is 50. But NH doesn't throw any error if set an higher value and I don't know the default value the.

Kris-I
I call it via:using (ISession sess = DBSessionManager.GetDBSession()) { using (var tx = sess.BeginTransaction()) { sess.SetBatchSize(50); foreach (var item in newItems) { sess.Save(item); } tx.Commit(); } }this does not change the batchsize nor does it enable batching.
urpcor
I think the line I gave you must be placed in the config file
Kris-I
I use Fluent Nhibernate where I set the batchsize and additionally change it afterwards: the first time the Batchsize changes(but batching itself doesnot work afterwards) but subsequentially calling SetBatchSize does not have any effect. FluentConfiguration cfg = Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(dbConnectionString)).AdoNetBatchSize(3).ShowSql()). Mappings(m => m.FluentMappings.AddFromAssembly(mappingAssembly)). Mappings(m => m.HbmMappings.AddFromAssembly(mappingAssembly));
urpcor
A: 

I have no idea if and how the NHProf reports batching but using the normal SQL Profiler you cannot notice it.

To verify how it works and if it is indeed enabled as I have set it up, I had to debug the NHibernate's code.

What NHinernate does is to add each generated SQL command in a collection of SQL commands that it is flushed (send to the DB) when the defined BatchSize is reached or when there are no more SQL commands to execute.

Observing the SQL profiler this is not noticable as SQL queries appear but actually NHibernate sends the commands in bactches to the DB.

This way if you want to execute 10 SQL statements without setting the BatchSize NHinerante will talk to the DB 10 times but setting the BatchSize to 10 then it will talk to the DB only once sending the all SQL queries in one go. Unfortunately this is not noticeable in the SQL Profiler...

tolism7
A: 

I'm using NHibernate Profiler to see if batching really occurs. Code looks like this

Session.NHibernateSession.SetBatchSize(data.Items.Count);
        foreach (var o in data.Items)
        {
            //something else...
            base.Save(o);
        }
        Session.NHibernateSession.SetBatchSize(0);

Profiler still gives me error "Large number of individual writes".

BTW Im using Fluent Nhibernate

Thnx

Amel Music
after update to the most recent NH version it worked~!!
urpcor