-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: NHibernate returns overwritten values
PostPosted: Mon Mar 13, 2006 3:57 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
I have a class Country with a corresponding table Country in the database. When I get the countries from the database using NHibernate, I get older values and not the current values of a record in the database. When I change 'England' to 'UK', save the object and call GetAll (see code excerpt below), I still get 'England' instead of 'UK' as expected. I checked in the database and the record has changed. Does NHibernate has some caching going on?

Hibernate version:
0.99.1.0

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="MyApp.Domain">
   <class name="Country" table="Country">

      <id name="ID" type="Int32" column="id" unsaved-value="0">
         <generator class="identity"/>
      </id>

      <property name="Name" column="name" type="String" length="50" />
   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
public IList GetAll(Type type, params string[] sortProperties)
    {
        ICriteria crit = session.CreateCriteria(type);
        if (sortProperties != null)
        {
            foreach (string sortProperty in sortProperties)
            {
                crit.AddOrder(Order.Asc(sortProperty));
            }
        }
        return crit.List();
    }

...

IList countries = GetAll(typeof(Country), null);


Name and version of the database you are using:
SQL Server 2005


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 5:03 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
I made a test application to show my problem. It's an ASP. NET 2.0 web application. On the page is a GridView where all records from the Country table are shown. When I edit a country, the old value is shown in the GridView instead of the value I just entered.
I'm starting to think it has something to do with handling NHibernate sessions within the ASP.NET application.
Can you anyone please take a quick look at my test application to see what's wrong? You can download it at http://members.chello.nl/n.gruson

Thanks in advance,
Jack


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 6:20 pm 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
Can it be possible that the ObjectDataSource caches results between postbacks? I don't think this issue has anything to do with NHibernate.

Btw, that GetAll() method looks very familiar ;)

_________________
Cuyahoga


Top
 Profile  
 
 Post subject: Same behaviour without GridView or ObjectDataSource
PostPosted: Wed Mar 15, 2006 3:21 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
I added a Test.aspx which does not use GridView or ObjectDataSource to rule out that these components are responsible for the problem. I still get the same behaviour in Test.aspx.

Link: http://members.chello.nl/n.gruson. Could anyone take a second look?

Thanks,
Jack


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 9:16 am 
Newbie

Joined: Sun Dec 11, 2005 12:22 pm
Posts: 5
I'm having the same problem with .NET 2.0 and 1.0.1 version of hibernate. No idea why it occurs.

_________________
Mattias Petter Johansson


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.