Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » eclipselink 2.4 TABLE_PER_TENANT shared EMF
eclipselink 2.4 TABLE_PER_TENANT shared EMF [message #902706] Mon, 20 August 2012 00:50 Go to next message
Justin Joe is currently offline Justin JoeFriend
Messages: 1
Registered: August 2012
Junior Member
I have an existing JavaEE app using

- eclipselink 2.4 (JPA 2.0)
- glassfish 3.1
- EJB 3.0
- PostgreSQL 9.1

I want to add multi-tenancy support and i should be able to change the schema at runtime.

Basically; i will have a different schema per tenant with the same types of tables in it. (this was a business decision for data isolation) (SaaS - shared DB, seperate schema)

i want the application to share the same EntityManagerFactory because creating it for every DB operation is very expensive and when i am creating EntityManagers for every single DB transaction, i want to pass tenant-discriminator (schema) and JDBC_USER.

it seems that eclipselink added this support at 2.4 and i went through this example

i have added these annotations in my Model classes

    @TenantTableDiscriminator(type = TenantTableDiscriminatorType.SCHEMA, 
            contextProperty = "eclipselink.tenant-id")

and in my @Stateless bean, there should be a way of passing in EMF

    private EntityManagerFactory emf ;

    EntityManager em = emf.createEntityManager();

so my question is :

How can i inject the shared EMF into my EJB beans ?

I am having a hard time getting this part working

// Shared EMF
    EntityManager em = createEntityManager(MULTI_TENANT_PU);
    em.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT, "gpelleti");

for this line;

EntityManager em = createEntityManager(MULTI_TENANT_PU);

1. Should 'createEntityManager' not be called through EMF
2. what is 'MULTI_TENANT_PU' type ?

Re: eclipselink 2.4 TABLE_PER_TENANT shared EMF [message #905015 is a reply to message #902706] Wed, 29 August 2012 15:01 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You should be able to call createEntityManager(Map) on your emf and pass a properties map that contains the MULTITENANT_PROPERTY_DEFAULT property.

Map properties = new HashMap();
properties.put(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT, "your-tenant");

James : Wiki : Book : Blog : Twitter
Re: eclipselink 2.4 TABLE_PER_TENANT shared EMF [message #998942 is a reply to message #902706] Fri, 11 January 2013 02:31 Go to previous message
sys alleys is currently offline sys alleysFriend
Messages: 3
Registered: January 2013
Junior Member
i am looking for this solution(TABLE_PER_TENANT) the one u implemented, is it working
and how you solved it? if you sheds some light on this solution it will be helpful
to all.
Previous Topic:Can I use ClipseLink to work with Object-Relational datatypes(TYPSES, VARRAY, NESTED TABLES..)
Next Topic:JPQL ignores OrderBy annotation when using JOIN FETCH
Goto Forum:

Current Time: Sat Jun 23 20:04:22 GMT 2018

Powered by FUDForum. Page generated in 0.01444 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top