Results 1 to 4 of 4

Thread: SimpleDelegatingSessionFactory second level cache key conflict

  1. #1
    Join Date
    Sep 2011
    Posts
    6

    Default SimpleDelegatingSessionFactory second level cache key conflict

    While using the SimpleDelegatingSessionFactory with multiple databases and second level , there is potential for cache key conflicts.
    This issue is also discussed here in more detail.

    Example from the link above:
    Database 1 with table "Employee" and record with an id of 5 would produce a cache key: NHibernate:Entities.EmployeeManagement.Employee:5@ 5

    Database 2 with table "Employee" and record with an id of 5 would also produce a cache key: NHibernate:Entities.EmployeeManagement.Employee:5@ 5 <- Conflict

    Setting the nhibernate property "cacheregionprefix" in the configuration would still leave the potential for a cache key conflict, as the configuration properties never change once read.

    To remedy this, an update to the SimpleDelegatingSessionFactory to attempt to read the cache region prefix from the
    logical thread context much like the connection string is currently read. The new cacheregionprefix is appended to the existing cacheregionprefix if present or sets the cacheregionprefix property before creating the SessionFactory related to the connection string.

    This is the updated version of SimpleDelegatingSessionFactory.txt. I will request a pull on github if this is update doesn't need to be changed.

  2. #2
    Join Date
    Jul 2010
    Posts
    245

    Default

    If you verify that this works, please do issue a pull request for it!

    Thanks,

    -Steve B.

  3. #3
    Join Date
    Sep 2011
    Posts
    6

    Default

    A minor change was made to restore the original cache region prefix, this is to prevent multiple cache region prefixes from being appended together. I have verified that the pull request listed below is creating the correct cache key names for a given database, and the cache keys are the same across SimpleDelegatingSessionFactory instances. The fix has been running in our test environment for about a month now with no problems.

    The pull request: https://github.com/SpringSource/spring-net/pull/15

    -- Jeremy

  4. #4
    Join Date
    Jul 2010
    Posts
    245

    Default

    Thanks; we'll review it. JIRA issue opened: https://jira.springsource.org/browse/SPRNET-1498

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •