-->
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.  [ 2 posts ] 
Author Message
 Post subject: Second Level Cache and External Database Updates
PostPosted: Tue Jan 09, 2007 7:08 am 
Newbie

Joined: Fri Sep 15, 2006 10:18 am
Posts: 8
Hi,

I'm using Hibernate 1.0.3 and this is generally working extremely well. However, I have a particular use case that I'm struggling to resolve. Part of my data model refers to tables that are maintained using ASP.NET web security libraries. When I call these libraries they may make database changes that occur outside of the scope of NHibernate therefore my second level cache is out of date.

As I understand it, in these situations I can use evict() on the on objects that I know to be out of date, however the next query that I run still returns the stale version of the data. Here is an example of my call to evict and the ASP.NET security:

Code:
      List<String> removeProfiles = new List<String>();

      string username = dmUser.Username;

      foreach (DomainModel.AspnetUsersInRoles tmp in dmUser.AspnetUser.AspnetUsersInRoles) {
        foreach (DomainModel.Profile profile in tmp.Role.Profiles) {
          // store profile names to remove using ASP.Net security methods later...
          removeProfiles.Add(profile.Name);

          // evict this object from the cache, forcing a refresh on next query
          mgr.evict(profile);
        }

        // evict this object from the cache, forcing a refresh on next query
        mgr.evict(tmp);
      }

      // evict this object from the cache, forcing a refresh on next query
      mgr.evict(dmUser);

      foreach (String profileName in removeProfiles) {
        Roles.RemoveUserFromRole(username, profileName);
      }

      // make sure that the updated user reflects underlying database changes.
      dmUser = mgr.GetUser(user.Id);


What am I doing wrong?! Any help on this matter will be greatly appreciated.

Best Regards,

Chris.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 4:13 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
If the second level cache is involved, you'll need to evict the object from there too.
Use SessionFactory.Evict() for this.


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