rhuan080 / multitenancyJpaJakartaEE

4 stars 4 forks source link

Provider does not support unwrapping javax.persistence.EntityManagerFactory to org.hibernate.engine.spi.SessionFactoryImplementor #4

Closed TimeMtsi closed 1 year ago

TimeMtsi commented 2 years ago

Hi I have used your example but I am getting issues with the entity manager factory this is the error I am getting Provider does not support unwrapping javax.persistence.EntityManagerFactory to org.hibernate.engine.spi.SessionFactoryImplementor, I have used the SessionFactoryImplementor as below.

final SessionFactoryImplementor sf = emf.unwrap(SessionFactoryImplementor.class); final MultiTenantResolver tenantResolver = (MultiTenantResolver) sf.getCurrentTenantIdentifierResolver(); tenantResolver.setTenantIdentifier(multitenancyIdentifier); return emf.createEntityManager();

rhuan080 commented 2 years ago

Hi @TimeMtsi

The code below works for you?

final MuiltiTenantResolver tenantResolver = (MuiltiTenantResolver) ((SessionFactoryImplementor) emf).getCurrentTenantIdentifierResolver();
tenantResolver.setTenantIdentifier(multitenancyIdentifier);

If not, can you tell me the Wildfly version? Are you using the Hibernate provided by Wildfly or you are using another version?

TimeMtsi commented 2 years ago

Hi @rhuan080 Thank you for your response, however that's the first code I implemented and got this error (java.lang.RuntimeException: class com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper cannot be cast to class org.hibernate.engine.spi.SessionFactoryImplementor (com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @3e6a9fec; org.hibernate.engine.spi.SessionFactoryImplementor is in unnamed module of loader org.glassfish.javaee.full.deployment.EarClassLoader @453f0ef6) note The full stack traces of the exception and its root causes are available in the Payara Server 5.201 #badassfish logs.

Payara Server 5.201 #badassfish)

rhuan080 commented 2 years ago

Hi @TimeMtsi

This code was tested just for WildFly. I`m not aware if it works to Payara Server.

TimeMtsi commented 2 years ago

Hi @rhuan080 Thank you for your response, that helps alot.