Is it possible to get the associated persistence unit name of an EntityManager object? For example, you have
@PersistenceContext( unitName="fooPU" )
private EntityManager em;
Is it possible to get the name fooPU
from em
? The motivation for this is that I want to have a small test to verify that the injected em through @Inject
is associated with the right persistence unit.
the persistance unit name is under the key "hibernate.ejb.persistenceUnitName" in the properties Map
String puName = em.getEntityManagerFactory().getProperties().get("hibernate.ejb.persistenceUnitName").toString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With