You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I use your example in my project but I found emf.getCurrentTenantIdentifierResolver() always returns the same instance. It is not thread safe since multiple racing threads might change the value of MultiTenantResolver.tenantIdentifier before calling emf.createEntityManager(). So to make it thread-safe, I use synchronized method to replace MultiTenantResolver.setTenantIdentifier() method to something like:
public class MultiTenantResolver implements CurrentTenantIdentifierResolver {
...
public synchronized EntityManager createEntityManagerWithThreadSafety(String tenantIdentifier, EntityManagerFactory emf) {
this.tenantIdentifier = tenantIdentifier;
return emf.createEntityManager();
}
...
}
Please let me know if you find a problem with my solution or if you have a better solution.
Thank you for this github project and your article. It saved me a lot of hours.
The text was updated successfully, but these errors were encountered:
Hi,
I use your example in my project but I found
emf.getCurrentTenantIdentifierResolver()
always returns the same instance. It is not thread safe since multiple racing threads might change the value ofMultiTenantResolver.tenantIdentifier
before callingemf.createEntityManager()
. So to make it thread-safe, I use synchronized method to replaceMultiTenantResolver.setTenantIdentifier()
method to something like:Please let me know if you find a problem with my solution or if you have a better solution.
Thank you for this github project and your article. It saved me a lot of hours.
The text was updated successfully, but these errors were encountered: