Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9222

HibernateTransactionManager does not support multi tenancy, Hibernate 4.1

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Last commented by a User:
      false

      Description

      HibernateTransactionManager always opens new session by invoking sessionFactory.openSession(). However with multi tenancy session should be opened by sessionFactory.withOptions().tenantIdentifier(tenantIdentifier).openSession().

      I managed to get it working with a few local modifications
      1)adding new property to HibernateTransactionManager, implementation of org.hibernate.context.spi.CurrentTenantIdentifierResolver
      2)using new property if present to open session in multi tenant way
      3)modification of key used to bind session to thread
      TransactionSynchronizationManager.bindResource(new MultiKey(sessionFactory,tenantIdentifierFromResolverOrNull), txObject.getSessionHolder());
      4)modification of key used by SpringSessionContext to retrive earlier created session when callin sessionFactory.getCurrentSession() in my app code

      Unfortunately this is not very neat solution to the problem and probably has some negative, unforeseen by me consequences.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              zlooo Krzysztof Dworakowski
              Last updater:
              Chris Beams
            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 46 weeks, 5 days ago