I am trying to change Java EE web application that use JPA2 and EJB3 to support multi tenancy.
I would like to make the setting of the current tenant id before my application request start so the application itself will not have to know it is used in multi tenant environment.
I am trying not to use vendor specific feature to allow myself deploy the application to both on-prem container and google AppEngine. That been said, if I can use vendor specific feature from external place such as servlet filter this will be great solution.
I am currently using Glassfish 3.1 as container and Hibernate 4.0 as JPA2 provider.
Sample code will be much appreciated.
Thank you,
Ido.
JPA does not define any specific multi-tenancy support. So it may be difficult to implement without using a provider specific feature.
You could have the same tables for each tenant, but in a different schema. You could then have a different persistence unit that had the same mappings, but set a different default schema in an additional orm.xml file.
For the multi-tenancy support in Glassfish through EclipseLink see,
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Single-Table_Multi-Tenancy