Eduardo
Eduardo

Reputation: 3

JSF + Wildfly connect in many databases dynamically

I have a Web Application using JSF + CDI + JPA and the Wildfly server. until this moment Wildfly are managing the transactions, auth security, email service... So my problem is that I need my system to access multiples databases. So that the client are logging in, he put their login and password and also select the database.

I already Googled a lot and solutions as multi-tenancy did not seem very interesting. I also thought of taking this responsibility of the server, making the connection in the application and still managing to use the injections usually, but I have a lot of troubles with it, like on security management and in all of things that Wildfly managed before.

Some tips or ideas on how to solve this problem?

Upvotes: 0

Views: 468

Answers (1)

Harald Wellmann
Harald Wellmann

Reputation: 12885

Check out Hibernate multitenancy with DATABASE mode. This works quite nicely in WildFly 10.

Basically, you just need to implement a MultiTenantConnectionProvider which provides a connection to the appropriate database for the current request.

This should solve your problem at the database level. You still need to figure out how to determine the correct database for the current request, e.g. deriving it from the URI of the current HTTP request and storing it in a @RequestScoped bean.

Upvotes: 1

Related Questions