Multi-Tenancy with Spring + Hibernate: “SessionFactory configured for multi-tenancy, but no tenant identifier specified”

前端 未结 6 1541
一个人的身影
一个人的身影 2020-12-13 20:58

In a Spring 3 application, I\'m trying to implement multi-tenancy via Hibernate 4\'s native MultiTenantConnectionProvider and CurrentTenantIdentifierResolver. I see that the

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 21:21

    As I explained in this article, Hibernate defines the CurrentTenantIdentifierResolver interface to help frameworks like Spring or Java EE to allow using the default Session instantiation mechanism (be it from an EntityManagerFactiry).

    So, the CurrentTenantIdentifierResolver must be set via a configuration property which is exactly where you went wrong because you didn't supply the right fully-qualified class name. The CurrentTenantIdentifierResolver implementation being CurrentTenantIdentifierResolverImpl, the hibernate.tenant_identifier_resolver has to be:

    com.afflatus.edu.thoth.context.CurrentTenantIdentifierResolverImpl
    

    After you fix this, when the HibernateTransactionManager calls getSessionFactory().openSession(), Hibernate will use the CurrentTenantIdentifierResolverImpl to resolve the tenant identifier.

提交回复
热议问题