Last active
December 6, 2017 09:58
-
-
Save kuhnroyal/8bfff9b1e652a7ed06a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultiTenantJpaTransactionManager extends JpaTransactionManager { | |
@Inject | |
private CurrentTenantResolver tenantResolver; | |
@Override | |
protected void doBegin(final Object transaction, final TransactionDefinition definition) { | |
super.doBegin(transaction, definition); | |
final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(getEntityManagerFactory()); | |
final EntityManager em = emHolder.getEntityManager(); | |
final Serializable tenantId = tenantResolver.getCurrentTenantId(); | |
if (tenantId != null) { | |
em.setProperty("eclipselink.tenant-id", tenantId); | |
} else { | |
// some error handling here | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment