Play 2.3+ Multi-tenancy (Schema/DB per tenant) example

461 views
Skip to first unread message

Nicolaas Frederick Huysamen

unread,
Sep 23, 2014, 2:09:31 AM9/23/14
to play-fr...@googlegroups.com
We are evaluating using Play for a new application, but one requirement is that we have shema (or db) per tenant multi-tenancy. Tenants are created dynamically (by creating their schema from a template). Are there any good examples of achieving this in Play? During the request we are able to figure out the tenant from the request headers, so a simple stateless approach will work great.

Thanks

Ian Rae

unread,
Sep 23, 2014, 10:42:45 AM9/23/14
to play-fr...@googlegroups.com
Play works well with Flyway, which does schema creation (and migration) programmatically.

   http://flywaydb.org/




Nicolaas Frederick Huysamen

unread,
Sep 24, 2014, 3:52:12 AM9/24/14
to play-fr...@googlegroups.com
Not quite what I was asking about though. I am interested in knowing how (or if) Play can do multi-tenancy with db/schema per tenant from a single app.

Earle Nietzel

unread,
Sep 24, 2014, 11:45:23 AM9/24/14
to play-fr...@googlegroups.com
Hi Nick,

Sounds like unified access to your tenant datasources is what your looking for.

Apache Spark might be a fit for your design..

Alberto Souza

unread,
Sep 24, 2014, 6:03:45 PM9/24/14
to play-fr...@googlegroups.com
There is nothing out of the box. Probably you will need to create an Action composition to decide which tenant is accessing your application and create the SessionFactory/EntityManagerFactory/WhateEverFactory based on that. Hibernate 4 has support for the schema approach. Here is the link => http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch16.html#d5e4771

Rajendra Prasad Gujja

unread,
Jan 13, 2016, 12:03:42 AM1/13/16
to play-framework
This is a little old post, but it may benefit other users like me.

I have put together an example on how Play + JPA (Hibernate) works to achieve multi-tenancy. It supports schema/database per tenant with the support of a common database which will have "common to all tenants" information.


Thanks,
Raj.

Felipe Alfaville

unread,
Jan 13, 2016, 1:39:04 PM1/13/16
to play-framework
Reply all
Reply to author
Forward
0 new messages