NHibernate Forge
The official new home for the NHibernate community

Get Started

Article
Comments (4)
History (20)
85% of people found this useful

Get Started

This article give you a guide on how to setup NHibernate.Burrow framework for you project.
Configration setting in the Config file:

   1: <configSections>
   2:      <section name="NHibernate.Burrow" type="NHibernate.Burrow.Configuration.NHibernateBurrowCfgSection, NHibernate.Burrow" />
   3:  </configSections>
   4:  <NHibernate.Burrow  >
   5:      <persistenceUnits>
   6:          <add name="PersistenceUnit1" nh-config-file="~/hibernate.cfg.xml"   />
   7:      </persistenceUnits>
   8:  </NHibernate.Burrow>

For web.config in ASP.NET applications, you also need to add a HttpModule Setting

   1: <httpModules>
   2:    <add name="NHibernate.Burrow.WebUtil.HttpModule"
   3:           type="NHibernate.Burrow.WebUtil.WebUtilHTTPModule,NHibernate.Burrow.WebUtil"/>
   4: </httpModules>


You'll need to maintain your hibernate configuration in the hibernate.cfg.xml (click here for a sample) or whatever file name you want. For multiple Databases, you just create a separate hibernate config file for each database and set you config as this:

   1: <configSections>
   2:      <section name="NHibernate.Burrow" type="NHibernate.Burrow.Configuration.NHibernateBurrowCfgSection, NHibernate.Burrow" />
   3:  </configSections>
   4:  <NHibernate.Burrow >
   5:     <persistenceUnits>
   6:          <add name="PersistenceUnitDB1" nh-config-file="db1hibernate.cfg.xml" />
   7:          <add name="PersistenceUnitDB2" nh-config-file="db2hibernate.cfg.xml" />
   8:     </persistenceUnits>
   9:  </NHibernate.Burrow>


That's pretty much it. If you only needs OpenSessionPerView, then the only interaction with Burrow is the following line

   1: ISession sess = new BurrowFramework().GetSession(); //Gets the Burrow Managed NHibernate Session

Please note that as the Session is managed by Burrow, you cannot call any method of it that will change the status or the transaction of it.
( If you are using Burrow.AppBlock.GenericDAO as your base DAO, then you probably don't need to explicitly get the managed session at all.)
If and only if the application is not in a ASP.NET environment, you will need to call BurrowFramework.InitWorkSpace to initialize the Burrow environment before any work that involves Burrow managed service such as NHibernate Session or Transaction. Also you need to call another method when a workUnit is done and you want to commit it. Afterwards, you will need InitWorkSpace() again before you use Burrow managed service

   1:  new BurrowFramework.InitWorkSpace();//call this at the beginning (only when not in ASP.NET)
   2:  new BurrowFramework.CloseWorkSpace();//call this at the end (only when not in ASP.NET)

Recent Comments

By: jandark Posted on 12-30-2009 12:49

Could you update Burrow for NH 2.1.2.

When I setup Burrow I get following error:

Could not load file or assembly 'NHibernate, Version=2.0.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

By: Karl Posted on 03-25-2009 16:06

I also needed to add preCondition="managedHandler" to the module in system.webServer for it to work.

By: Min.Han Posted on 03-16-2009 12:13

@Shay Jacoby,

One question, when moving to the IIS7 box did you put the httpModules in the <system.webServer> section?

www.west-wind.com/.../168221.aspx

By: Shay Jacoby Posted on 03-03-2009 20:55
100% of people found this useful

Thanks a lot for this clear explanation.

Today I integrated the NHibernate.Burrow framework into my ASP.NET (MVC) Application, the url: http://www.heymann-films.com/

The Service layer, data (NHibernate of course) layer are 2 different class libraries.

On local environment everything worked perfect but when upload to shared hosting Server (iis7) there was an error:

"Either workspace is not initialized yet or it is closed"

Unfortunately there are only 2 different relevant results for this error in google so I tried many solutions.

Finally, The only solution that worked was to add to events to global.asax :

protected void Application_BeginRequest(object sender, EventArgs e)

       {

           new BurrowFramework().InitWorkSpace();

       }

       protected void Application_EndRequest(object sender, EventArgs e)

       {

           new BurrowFramework().CloseWorkSpace();

       }

Now it works.

Thx.

View All
Powered by Community Server (Commercial Edition), by Telligent Systems