Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @Multitenant guidelines
@Multitenant guidelines [message #895593] Fri, 13 July 2012 17:28 Go to next message
Andriy Zhdanov is currently offline Andriy ZhdanovFriend
Messages: 6
Registered: June 2012
Junior Member

Could someone please help me to understand how to use @Multitenant in context of these two problems:

1) How to set orm mapping per tenant, using EMF per tenant?

2) Not using EMF per tenant, how entityManager.setProperty(MULTITENANT_PROPERTY_DEFAULT, <name>) is supposed to work in multi threading? Are EntityManager properties per thread?

3) Using EntityManager per tenant, 'drop-or-create-tables' ddl.generation droops table on every create, i.e. per tenant. Is it designed?

Thank you.
Re: @Multitenant guidelines [message #895956 is a reply to message #895593] Mon, 16 July 2012 16:03 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1376
Registered: July 2009
Senior Member

1) You don't exactly set one orm.xml per tenant. Instead, you would have one orm.xml with shared mappings and then override it for individual tenants.
Here is a simple multitenant example using a shared orm.xml:

Extending the shared mappings is done using a MetadataSource as described here:
A more complex example of multitenant mentioned in the above is here:

2) EntityManagers should not be shared amongst threads, so I'm not sure what you mean. Each thread should obtain a new EntityManager as required - they are not thread safe.

3) Drop-and-create is as designed. Each login will attempt to drop tables and recreate them. It is not meant only to be used with development where the schema frequently can change and need to be recreated, and won't work well with multitenant apps as each tenant will log in with its own ootentially different metadata. You may want to use just the create table option, or the new "create-or-extend-tables" feature with multitenant apps.

Best Regards,
Re: @Multitenant guidelines [message #896205 is a reply to message #895956] Tue, 17 July 2012 14:51 Go to previous message
Andriy Zhdanov is currently offline Andriy ZhdanovFriend
Messages: 6
Registered: June 2012
Junior Member
Hi Chris,

Thank you for your answer, it is very clear now. Strange I did not find mysports example myself, and those pages were not so clear before.

I have further question, though, if you don't mind.

Regarding 'Multitnant' doc, 1st item in the thread, about 'Persistence Usage for Multiple Tenants'

Do you have any idea, how @PersistenceUnit and/or @PersistenceContext container managed injection can be used with multi-tenancy?

I understand one can do the following in managed bean:

    @PersistenceContext(unitName = "myPU")
    EntityManager em;

Though, it's not possible to make it variable.

Thank you.
Previous Topic:Dynamic entities: adding properties after initialization
Next Topic:cannot use eclipselink 2.x
Goto Forum:

Current Time: Tue Jan 26 07:07:04 GMT 2021

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

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

Back to the top