You can just add another "property" inside the "properties" part of file persistence.xml.
Example:
<persistence-unit name="pu-foo" transaction-type="JTA">
<jta-data-source>jdbc/some-name</jta-data-source>
<!-- other fields/properties -->
<properties>
<property name="persistence-unit-name" value="pu-foo" />
<!-- other fields/properties -->
</properties>
</persistence-unit>
And, inside your java code, let suppose you have an EntityManager called myEM...
System.out.println(myEM.getEntityManagerFactory().getProperties().get("persistence-unit-name"));
Or...
System.out.println(myEM.getProperties().get("persistence-unit-name"));
The property "persistence-unit-name" appears in properties of both myEM and myEM.getEntityManagerFactory().
That would print "pu-foo"
I hope that could help someone that still have this need.
entityManager.getEntityManagerFactory().getProperties()
) might contain the PU name – GreeleygetEntityManagerFactory()
, i.e., I useentityManager.getProperties()
, which gives the same property map as yours. But that map doesn't have a standalone PU name key. It does have the PU name embedded in some other keys, though. You can get the PU name with some hacking, but it just doesn't seem clean to me. – Cornhusking