-->
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.  [ 4 posts ] 
Author Message
 Post subject: disable Session cache or force refresh of many-to-one
PostPosted: Tue Jul 24, 2007 1:31 pm 
Newbie

Joined: Tue Jul 24, 2007 1:07 pm
Posts: 5
Dear nHibernate developers,

Among other classes I have two classes: User and TourGroup those participate in many-to-one relationship. So User has a property TourGroup. Note: I do not need and do not implement one-to-many relationships (via collections), only many-to-one via single property. I use ADO.NET SQL queries for working with one-to-many and it is fine for me.

When I load User1 I do a refresh to see if any changes were done externally (by ADO.NET or programs running on other hosts), and it works fine. If it is a first User loaded from the database then its TourGroup1 is fresh too. But when later I load User2 which may refer to the same TourGroup1 and doing refresh on User2 I get a fresh copy of User2 but TourGroup1 may be expired, cached version of it loaded together with User1 is used. So if any external changes to TourGroup1 has been made since loading User1 they are not available in TourGroup1 object until explicitelly refreshing it like Session.Refresh(User2.TourGroup).
Reason: It is not convenient to manually refresh each object in a long hierarchy of objects like:
User2
User2.TourGroup
User2.TourGroup.PSHost
etc.


Please suggest:
1) Is it possible somehow to tell nHibernate to automatically refresh all many-to-one related objects when many side is refreshed? So when Session.Refresh(User2) would be called it would automatically refresh User2.TourGroup too.

2) Is it possible to completelly disable Session (first level) cache?

3) Is it correct that SessionFactory (second level) cache is disabled by default if no cache assemblies are placed to the bin directory and no config instructions for cache provided?

Thanks, Alex
www.aulix.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 4:57 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
You could evict the TourGroup from the Session, or use a new Session, or if the problem is that you are worried about concurrency, you could do optimistic locking.


Top
 Profile  
 
 Post subject: evict does not help
PostPosted: Tue Jul 24, 2007 10:08 pm 
Newbie

Joined: Tue Jul 24, 2007 1:07 pm
Posts: 5
I tried following code:

Public Function Evict(Optional ByVal T As Type = Nothing)
NHS.Evict(Me)
If Not IsNothing(T) Then
NHS.SessionFactory.Evict(T, Id)
End If
End Function

but it does not help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 4:40 am 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
Hi aulix!

Just a sentence from the NHibernate Reference
Quote:
NHibernate will evict associated entities automatically if the association is mapped with cascade="all" or cascade="all-delete-orphan".

_________________
WBR, Igor


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