Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] eclipselink 2.4 TABLE_PER_TENANT shared EMF

Hi Guy,

thanks for the answer.

the problem is actually injecting the PU. Because when I was using container-managed transactions and leaving the management to the app-server, i was going like this
@PersistenceContext
protected EntityManager em ;

EMF was being taken care of by the app-server but now i have to create or reference it somehow and i dont know how ?

and the second thing is that i tried to use non-shared EMF example too and set 'eclipse-tenant-id' to the schema that i am getting dynamically
when i debugged it, it seems like it is working but it is actually querying from the default schema 'public' even though i specify a different schema which the DB user has permission on.
so i can't get it working to query from different schemas basically.

any help at this point would be much appreciated

cheers,
Justin

On 8/21/2012 5:19 AM, Guy Pelletier wrote:
Hi Justin,

To answer your questions

1 - Yes, the EM should be created through the EMF. The sample code you are seeing is from our testing framework and the createEntityManager method is simply a wrapper to an emf.createEntityManager() call.

2 - MULTI_TENANT_PU is simply the name of the persistence unit since we have many different persistence units in our testing suites. If you are injecting the PU you don't need to worry about this.

Cheers,
Guy


On 21/08/2012 4:16 AM, Justin Joe wrote:
hi,

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 ?

thanks in advance




_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green
              Oracle Oracle is committed to developing practices and products that help protect the environment



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top