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.  [ 13 posts ] 
Author Message
 Post subject: Urgent help required : Not able to fetch updated data
PostPosted: Thu Apr 10, 2008 2:45 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
Hello,
I have a business entity named ChargeActivity, and I am not using second level caching nor am I using query caching. I fetch an object of ChargeActivity as

Ilist result = _session.CreateQuery(Predicate).SetCacheable(false).List();

No I go the database an fire a query and change one of the column against charge activty and now I again call

Ilist result = _session.CreateQuery(Predicate).SetCacheable(false).List();

unfortunately I don't get the updates. But I see that NHibernate fires query to the database.

In file Loader.cs , there is one method as
DoQuery(ISessionImplementor session,QueryParameters queryParameters,bool returnProxies)

In this methods there is one statement as
IDataReader rs = GetResultSet(st, selection, session);

Which actualy fires the query and gets the updated result in variable rs.

But further there is call to method GetRowFromResultSet which in turn calls method GetRow, and in method GetRow

it checks whether the object already exists in the cache(first level) and returns if found, therefore updates are not available

obj = session.GetEntity(key);
if (obj != null)
{
//its already loaded so dont need to hydrate it
InstanceAlreadyLoaded(rs, i, persisters[i], key, obj, lockModes[i], session);
}
else
{
obj = InstanceNotYetLoaded(rs, i, persisters[i], key, lockModes[i], optionalObjectKey, optionalObject, hydratedObjects,session);
}

return obj;


Why does it fire query to database and also check whether the object is in local cache? Also even if the object exists in the local cache it is not updated with the result set newly fetched from the database.
Can someone please help?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 5:47 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I'm not 100 percent sure, but try to eplain what happens. You load the objects in a session and keep that session. When you query for the second time, hibernate has to query the database since there could be new/deleted objectes. After retrieving the object hibernate checks if the objects are already in the session, which they are. Changes to the objects are only detected, if you have a version or timestamp column specified in the mapping, which I suppose you don't have. So hibernate thinks the objects are the same and does neither create new objects nor update the exisiting ones.

There are two ways to prevent that. One is using a version or timestamp column, the other is do a session.Refresh(obj). The latter will work for the already loaded object, but you won't see new/deleted objects.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 7:30 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
Thanks for your reply.
I have a couple of question :
What does version and timestamp stand for?
And where do we set this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 7:56 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Both are columns/properties which keep track of the state of a an object. Have a look at the documentation:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/mapping.html#mapping-declaration-version

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/manipulatingdata.html#manipulatingdata-updating

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:14 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
I am a bit confused

should the declaration be as


<class name="FIG.FIGMD.BusinessEntities.ViewChargeActivityDetails,FIG.FIGMD.BusinessEntities" table="ViewChargeActivityDetails" lazy="false" dynamic-update="true">
<id name="ChargeActivityUid" column="ChargeActivityUid" type="Guid">
<generator class="assigned"/>
</id>

<version column="ModifiedDate" name="ModifiedDate" type="timestamp"/>

<property column="ModifiedDate" type="DateTime" name="ModifiedDate" />
</class>


OR Should it be as



<class name="FIG.FIGMD.BusinessEntities.ViewChargeActivityDetails,FIG.FIGMD.BusinessEntities" table="ViewChargeActivityDetails" lazy="false" dynamic-update="true">
<id name="ChargeActivityUid" column="ChargeActivityUid" type="Guid">
<generator class="assigned"/>
</id>



<property column="ModifiedDate" type="DateTime" name="ModifiedDate"
<version column="ModifiedDate" name="ModifiedDate" type="timestamp"/>
/property>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:21 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I would say just the version, no additonal property, since the version mapping already specifies the property.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:24 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
I think I have confused you too,
In the first example <version> is child to <class>, whereas in the second one it's child to <property>.

Which one is correct ? is it a class level attribute or property level.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:36 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
class level

btw. you can put the nhibernate schema definitions in C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas and you will get intelli sense for the mappings. Saves you a lot of time and lookup.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:44 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
I tried this, but didn't work

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="FIG.FIGMD.BusinessEntities.ChargeActivity,FIG.FIGMD.BusinessEntities" table="ChargeActivity" lazy="false" dynamic-update="true">

<id name="ChargeActivityUid" column="ChargeActivityUid" type="Guid">
<generator class="assigned"/>
</id>

<version column="ModifiedDate" name="ModifiedDate" type="Timestamp"/>
<!--<timestamp column="ModifiedDate" name="ModifiedDate" access="property" />-->

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


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="FIG.FIGMD.BusinessEntities.ChargeActivity,FIG.FIGMD.BusinessEntities" table="ChargeActivity" lazy="false" dynamic-update="true">

<id name="ChargeActivityUid" column="ChargeActivityUid" type="Guid">
<generator class="assigned"/>
</id>

<timestamp column="ModifiedDate" name="ModifiedDate" access="property" />

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



Any Idea?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:48 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What do you mean with "didn't work" ? Do you still have the same problem as in your initial post ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 8:53 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
Yes I queried the same object , in the same session but didn't get any updates While modifying the row in database I had also updated column ModifiedDate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 9:14 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
If that's still the case, I'm afraid my assumption that version/timestamp would solve that problem were wrong :-(. Checkout chapter 10 (http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/transactions.html), maybe you find some hints there.

Another possibility if you only want to reload the already loaded objects is to call session.Refresh() on these objects.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 9:26 am 
Beginner
Beginner

Joined: Tue Sep 11, 2007 5:57 am
Posts: 36
Thanks for all your help. If <timestamp> and <version> foes not work,
then how does NHibernate handle changes made by other users in distributed enviorement. Suppose I fetch an object of Order and within next few seconds the same object is modified by some other user using NHibernate or directly through database, now until I use the same session I will always get the older version.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.