Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MongoDB and multi-tenancy(How to enable multi-tenancy for MongoDB persistence units)
MongoDB and multi-tenancy [message #1385844] Wed, 11 June 2014 15:24 Go to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 72
Registered: July 2009

I am trying to use MongoDB via EclipseLink and to enable multi-tenant support.

I started from the EclipseLink Address/Customer/Order/OrderLine example which works fine with MongoDB, then I started adding the multi-tenant specific annotations.

In my first try I specified the annotations to use a discriminator column for holding the tenant-id, and this did not work and EclipseLink raises an exception claiming that the requested feature is not supported for NoSQL platforms.

I then reverted to the TABLE_PER_TENANT method of partitioning data, and this time the EntityManager is created and I am able to save orders to the database.

However, Multi-tenancy settings seem to be ignored, infact, the MongoDB for the Order entity is called ORDER and is not suffixed with the tenant identifier, as I would have expected given that the default behaviour for TABLE_PER_TENANT is to suffix the table name (at least according to the annotation javadoc).

public class Order implements Serializable 

Here is the sample code I am using to try to insert data for two tenants:

        Map properties = new HashMap();

        properties.put(PersistenceUnitProperties.SESSION_NAME, tenantId);
        properties.put(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenantId);
        properties.put(PersistenceUnitProperties.MULTITENANT_SHARED_EMF, Boolean.FALSE.toString());

        EntityManagerFactory factory = Persistence.createEntityManagerFactory("mongo", properties);

        EntityManager em = factory.createEntityManager(properties);
        em.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT, tenantId);
        Order o1 = new Order();

I am calling the above code twice from a main, using different value for the tenantId variable, but the above results in two entries in the same collection named ORDER

I also tried forcing the tenant-id in the entity manager, both before and after opening the transaction (btw which is the correct way?) with no luck:

em.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT, tenantId);

Can anyone give me some advice? Thanks

Developing for Virgo using PDE:
Global JNDI in Virgo:
Hyperic to monitor Virgo:
Profile Virgo with JProfiler
Re: MongoDB and multi-tenancy [message #1386531 is a reply to message #1385844] Wed, 18 June 2014 07:10 Go to previous message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 72
Registered: July 2009

over 2000 views and no reply, no one is using MongoDB with Eclipse Link multi-tenancy?

Previous Topic:Multitenancy & single table inheritance
Next Topic:Unmapped attributes of superclass have wrong value
Goto Forum:

Current Time: Mon Nov 30 02:53:44 GMT 2015

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

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