Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to share EntityManagerFactory when different MetaDataSource per tanant
How to share EntityManagerFactory when different MetaDataSource per tanant [message #810683] Thu, 01 March 2012 12:22 Go to next message
pin xia is currently offline pin xiaFriend
Messages: 1
Registered: March 2012
Junior Member
I am using eclipselink 2.3.2 and trying its multi-tenancy and extensible entity features.
I defined an entity class A (Ignored other annotations and attributes)

@Multitenant(SINGLE_TABLE)
@VirtualAccessMethods
@TenantDiscriminatorColumn(name = "TENANT_ID", length = 12, contextProperty = "t.id")
@Entity
public class A{

@Transient
protected Map<String, Object> extensions = new FastMap<String, Object>();

@SuppressWarnings("unchecked")
public <T> T get(String name){
return (T) extensions.get(name);
}

public Object set(String name, Object value){
return extensions.put(name, value);
}
}

I also defined a class MyMetadataSource which implements MetadataSource.
MyMetadataSource class gets different extension metadata for different tenant.

There are two lines in persistence.xml
<property name="eclipselink.multitenant.tenants-share-emf" value="false" />
<property name="eclipselink.metadata-source" value="MyMetadataSource" />

Eveything works well as my expected. different EMF can be created for different tenant.

But the problem is one EMF per tenant is two heavy, I want to share the "public" metadata which is annotated in class A. The "private" metadata will be got at rumtime for different tenant. Is it possible?

I found there is a description from MySports example
http___://wiki.eclipse.org/EclipseLink/Examples/MySports
to describle this, but I am not quite understand it, anyone can give me the help?

When developing an application that can handle requests from multiple tenants you can choose to have a single EntityManager Factory (EMF) with tenant scoped EntityManagers (EM) or you can choose to have a EMF per tenant.
Re: How to share EntityManagerFactory when different MetaDataSource per tanant [message #810872 is a reply to message #810683] Thu, 01 March 2012 16:29 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If you want different tenants to have different metadata, then I can't see any other way than having multiple EMFs.

What do you mean by too heavy?

You can have a single EMF if all tenants share the same metadata.

If the are some classes that are shared, and others that have there own metadata, then you could have one shared persistence unit for the common data, and another separate persistence unit that used extended metadata.


James : Wiki : Book : Blog : Twitter
Previous Topic:[SOLVED] Transform instruction SQL (PostgreSQL) to JPQL (@NamedQuery)
Next Topic:Find after persist - ignoring cache
Goto Forum:
  


Current Time: Thu Apr 25 07:02:57 GMT 2024

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

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

Back to the top