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 Joe
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

http://wiki.eclipse.org/EclipseLink/DesignDocs/Multi-Tenancy/TablePerTenant

i have added these annotations in my Model classes

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


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

    @Inject
    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.getTransaction().begin();
    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 Sutherland
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");
emf.createEntityManager(properties);


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 alleys
Messages: 3
Registered: January 2013
Junior Member
Hi,
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: Wed Sep 17 05:55:21 GMT 2014

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

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