Multi tenant wildfly and JSF

268 views
Skip to first unread message

Adriano Aguiar

unread,
Jan 25, 2021, 12:45:09 PM1/25/21
to WildFly
Hello, I configured my project to work multi tenant in JPA, but I want to pass the name of company registrations through the url and I would like to see if I could do it that way?


My jboss-web.xml looks like this:

jboss-web>
    <context-root>/company</context-root>
</jboss-web>

grato,


Roberto Tatemoto

unread,
Jan 26, 2021, 10:02:42 AM1/26/21
to WildFly
Hi Adriano,

I hacked this multi-tenancy from Tomcat, Spring and MySql :)

I run on Wildfly 20.0.1, MySql 8 and Hibernate embedded in Wildfly

IMPORTANT: this solution is Hibernate dependent, don´t work in others providers.

1) The Hibernate Multi-tenancy need connect to one schema in start-up, then alter the persistence.xml to connect on schema. The schema assigned in the standalone.xml isn´t used.
  
   The values "javax.persistence.xxxxx" don´t work, only "hibernate.xxxxxx"

   Observe the many XXXXXX values to change to your application values (persistence-unit, password, etc.)

2) In case the change in schema (e.g. include new tables, columns), the Hibernate only make in the schema assigned in persistence.xml.
   Others schema aren´t changed and must be changed manually.
   
2) Include multi-tenancy properties in the persistence.xml.
   My application I use on database with many schemas: <property name="hibernate.multiTenancy" value="SCHEMA" />

3) Include in the web.xml the filter for multi-tenancy
   <filter>
<filter-name>PageFilter</filter-name>
<filter-class>br.com.e8Sys.repository.common.TenantFilter</filter-class> 
</filter>

   The TenantFilter class filter class takes the tenancy from the URL, and in my applthe tenancy is the same name of the schema in database
   e.g: the URL is https://company.e8sys.com.br

   You need adapt the TenantFilter class to take the tenancy from http://localhost:8080/company/

4) Java files attacheds, adapt and compile all.

5) In the standalone.xml include the datasource parameters without any change

6) I don´t use the jboss-web.xml file

7) The original source I extratecd from https://www.youtube.com/watch?v=AUcwQcgIahU (for Portuguese audience)

8) I research too in Hibernate fórum, but unfortunately I missed this links

Roberto Tatemoto
Sorocaba Brazil
persistence.xml
Tenant.java
TenantFilter.java
SchemaCurrentTenantIdentifierResolver.java
SchemaMultiTenantConnectionProvider.java
Reply all
Reply to author
Forward
0 new messages