3

I am using Rhino.Security repository to manage my users/roles.
The process of creation, deletion and association works fine but I am facing a problem when I query using one method: GetAssociatedUsersGroupFor.
The first time I call the method I don't get any groups for my user cause I haven't created any association yet. At this point I associate a user with a couple of groups.
I check in the DB and I can see the association.
Now I call again GetAssociatedUsersGroupFor but I can't get any groups.
With the profiler I've seen that the database isn't involved this time. I've checked the code and I've found that the function uses a Nhibernate SetCacheable:

    public virtual UsersGroup[] GetAssociatedUsersGroupFor(IUser user)
    {
        ICollection<UsersGroup> usersGroups =
            SecurityCriterions.AllGroups(user)
                .GetExecutableCriteria(session)
                .AddOrder(Order.Asc("Name"))
            .SetCacheable(true)
            .List<UsersGroup>();
        return usersGroups.ToArray();
    }

Since I don't want to change Rhino.Security code, I would like to know if I can override or change this behaviour in any way.

UPDATE:

I use this instruction to get associated groups:

AuthorizationRepository.GetAssociatedUsersGroupFor(User);

I associate with this code:

AuthorizationRepository.AssociateUserWith(User, grpName);

and detach:

AuthorizationRepository.DetachUserFromGroup(User, groupToRemove.Name);

UPDATE

I've found out that I had left the second level cache in my config:

<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>

I thought it was a good thing to have a II level cache, to improve the performance but, it seems I was totally wrong.
Is there anyone who can try to help me to understand what's happening here?

LeftyX
  • 35,328
  • 21
  • 132
  • 193
  • Can you post your code where you're saving the new associations and subsequently retrieving them? – nkirkes Feb 01 '11 at 18:10
  • @mannish: I've attached the code. It's very simple. As I said I can find the records in the DB so everything works fine. I've recompiled the Rhino.Security module with a comment here: .SetCacheable(true) and everything works fine but I would like to avoid that. – LeftyX Feb 01 '11 at 19:40
  • And just so I'm clear, this is taking place in separate NHib sessions right? You're not doing all of this under a single session? If the records are ending up in the database, I'm assuming they are different sessions/transactions. – nkirkes Feb 01 '11 at 20:40
  • @mannish:yes cause my app is ASP.NET MVC.I open a session a save data. The session is closed then. If I try to change the data I open another session, fetch the data and I notice that the query returns the previous infos, before the save. – LeftyX Feb 02 '11 at 08:19

1 Answers1

1

There's a problem with rhino.security.
I've managed to solve the problem, even if I don't like it.
I've called SessionFactory.EvictQueries() when I change an association and everything works fine.

LeftyX
  • 35,328
  • 21
  • 132
  • 193