org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified

Hibernate JIRA | Oriel Maute | 5 years ago
  1. 0

    [HHH-7312] Validate multi-tenancy configuration (if configured) during JPA bootstrap - Hibernate JIRA

    atlassian.net | 11 months ago
    org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified
  2. 0

    I tried to use db schema based multi tenancy with hibernate jpa / entitymanager. I use the following properties in persistence.xml: <property name="hibernate.multiTenancy" value="SCHEMA"/> <property name="hibernate.tenant_identifier_resolver" value="com.xoricon.persistence.bo.multitenancy.test.SchemaBasedTenantResolver"/> <property name="hibernate.multi_tenant_connection_provider" value="com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenantConnectionProvider"/> Both instances (SchemaBasedTenantResolver / SchemaBasedMultiTenantConnectionProvider) will be instantiated by hibernate. When i call: EntityManagerFactory lEntityManagerFactory= Persistence.createEntityManagerFactory("orm1"); EntityManager lManager = lEntityManagerFactory.createEntityManager(); I get: System.out: SchemaBasedMultiTenantConnectionProvider.getAnyConnection() System.out: SchemaBasedTenantResolver.<init>() E Time: 1,53 There was 1 error: 1) test1(com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest)org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified at org.hibernate.internal.AbstractSessionImpl.<init>(AbstractSessionImpl.java:82) at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:231) at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1831) at org.hibernate.ejb.EntityManagerImpl.getRawSession(EntityManagerImpl.java:121) at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:98) at org.hibernate.ejb.AbstractEntityManagerImpl.setDefaultProperties(AbstractEntityManagerImpl.java:268) at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:180) at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:90) at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:178) at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:173) at com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.test1(SchemaBasedMultiTenancyTest.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.main(SchemaBasedMultiTenancyTest.java:51) FAILURES!!! Tests run: 1, Failures: 0, Errors: 1 In System.out "SchemaBasedTenantResolver.<init>()" shows, that my CurrentTenantIdentifierResolver has been instantiated. But Hiberante did not call method "public String resolveCurrentTenantIdentifier()". I expect, that Hibernate uses the CurrentTenantIdentifierResolver to get the current tenant id. In JPA i cannot set the tenant on the Session, because the exception above occures before Session has been created. I can access the Session only by EntityManager.getDelegate(). But as shown above, i cannot create an EntityManager instance.

    Hibernate JIRA | 5 years ago | Oriel Maute
    org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified
  3. 0

    I tried to use db schema based multi tenancy with hibernate jpa / entitymanager. I use the following properties in persistence.xml: <property name="hibernate.multiTenancy" value="SCHEMA"/> <property name="hibernate.tenant_identifier_resolver" value="com.xoricon.persistence.bo.multitenancy.test.SchemaBasedTenantResolver"/> <property name="hibernate.multi_tenant_connection_provider" value="com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenantConnectionProvider"/> Both instances (SchemaBasedTenantResolver / SchemaBasedMultiTenantConnectionProvider) will be instantiated by hibernate. When i call: EntityManagerFactory lEntityManagerFactory= Persistence.createEntityManagerFactory("orm1"); EntityManager lManager = lEntityManagerFactory.createEntityManager(); I get: System.out: SchemaBasedMultiTenantConnectionProvider.getAnyConnection() System.out: SchemaBasedTenantResolver.<init>() E Time: 1,53 There was 1 error: 1) test1(com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest)org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified at org.hibernate.internal.AbstractSessionImpl.<init>(AbstractSessionImpl.java:82) at org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:231) at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1831) at org.hibernate.ejb.EntityManagerImpl.getRawSession(EntityManagerImpl.java:121) at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:98) at org.hibernate.ejb.AbstractEntityManagerImpl.setDefaultProperties(AbstractEntityManagerImpl.java:268) at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:180) at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:90) at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:178) at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:173) at com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.test1(SchemaBasedMultiTenancyTest.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.main(SchemaBasedMultiTenancyTest.java:51) FAILURES!!! Tests run: 1, Failures: 0, Errors: 1 In System.out "SchemaBasedTenantResolver.<init>()" shows, that my CurrentTenantIdentifierResolver has been instantiated. But Hiberante did not call method "public String resolveCurrentTenantIdentifier()". I expect, that Hibernate uses the CurrentTenantIdentifierResolver to get the current tenant id. In JPA i cannot set the tenant on the Session, because the exception above occures before Session has been created. I can access the Session only by EntityManager.getDelegate(). But as shown above, i cannot create an EntityManager instance.

    Hibernate JIRA | 5 years ago | Oriel Maute
    org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Schema level Issue on Multi tenancy in hibernate with postgresql

    Stack Overflow | 1 year ago | Firefox101
    org.hibernate.HibernateException: SessionFactory was not configured for multi-tenancy
  6. 0

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

    pr8x.com | 11 months ago
    org.hibernate.HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.HibernateException

      SessionFactory configured for multi-tenancy, but no tenant identifier specified

      at org.hibernate.internal.AbstractSessionImpl.<init>()
    2. Hibernate
      SessionFactoryImpl$SessionBuilderImpl.openSession
      1. org.hibernate.internal.AbstractSessionImpl.<init>(AbstractSessionImpl.java:82)
      2. org.hibernate.internal.SessionImpl.<init>(SessionImpl.java:231)
      3. org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1831)
      3 frames
    3. Hibernate EJB
      EntityManagerFactoryImpl.createEntityManager
      1. org.hibernate.ejb.EntityManagerImpl.getRawSession(EntityManagerImpl.java:121)
      2. org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:98)
      3. org.hibernate.ejb.AbstractEntityManagerImpl.setDefaultProperties(AbstractEntityManagerImpl.java:268)
      4. org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:180)
      5. org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:90)
      6. org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:178)
      7. org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:173)
      7 frames
    4. com.xoricon.persistence
      SchemaBasedMultiTenancyTest.test1
      1. com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.test1(SchemaBasedMultiTenancyTest.java:40)
      1 frame
    5. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      3 frames
    6. com.xoricon.persistence
      SchemaBasedMultiTenancyTest.main
      1. com.xoricon.persistence.bo.multitenancy.test.SchemaBasedMultiTenancyTest.main(SchemaBasedMultiTenancyTest.java:51)
      1 frame