views:

100

answers:

3

Hi all, I am using NHibernate to as the Data Access layer for my ASP.NET MVC application. I am also using Structure Map as an IoC container. I have configured Structre map to create a session factory as a singleton and create sessions on a per request basis (InstanceScope.Hybrid). I am able to do basic CRUD operations just fine.

Now, I have a background process running every 30 seconds, which uses a few repositories(which in turn use sessions). And this background process is unable to pick up the new data for some reason. Maybe I am missing a simple thing. I tried googling but was unable to find anything useful. It would really help me if someone pointed me in the right direction.

EDIT:

I am not sure if I have the second level cache enabled, I am a newbie with NHibernate, My hibernate configuration file is pasted below.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=Map.db;Integrated Security=True</property>
    <property name="show_sql">true</property>
    <mapping assembly="Infrastructure"/>
  </session-factory>
</hibernate-configuration>

The main thing I want to know is, if there is a design/design pattern which is already used in typical web applications using NHibernate. And would using Stateless sessions solve the problem, if my database settings are updated from a different app?

+1  A: 

If you have the second-level cache enabled, yet have a background process that is updating the database without going via NHibernate, then you won't see these changes coming through. In this scenario, using the second-level cache is not appropriate.

David M
A: 

Do you use a new sssion each time(30 secs) before you fire retreive in your backgroup application?

enable show_sql in hibernate config or use hiberante profiler or sql profiler to look for whether the sql is fired each time(30 secs).

it's hard to solve your problem with your description.

Sathish Naga
A: 

I solved this problem by creating a separate console application just for this purpose. Wasn't an elegant solution, but it still worked. Thanks for all your answers.

Khaja Minhajuddin