openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Bauer" <>
Subject Re: Getting the persistence unit name from an EntityManagerFactory
Date Tue, 06 May 2008 15:10:23 GMT
Hi Roger,

If you are able to use the OpenJPA interfaces directly (as opposed to
purely using the implementation agnostic JPA interfaces) you can use
the OpenJPA SPI to get the pu name from the emf.  Here is some sample

        EntityManagerFactory emf =

        if (emf instanceof
          org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI ojemf =
            (org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI) emf;
          org.apache.openjpa.conf.OpenJPAConfiguration ojc =
          System.out.println("pu name: " + ojc.getId());

The doc for the getId method indicates that it may return the PU name
or some other more-unique value for the current environment.  A quick
scan showed that the id should == the pu name unless you are in a
distributed db/slice environment.  (I could have missed something

If you need to find the pu name from an em you can get the OpenJPA emf
with this code:

        EntityManager em = emf.createEntityManager();
        org.apache.openjpa.persistence.OpenJPAEntityManager ojem =
        org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI ojemf =


On 5/4/08, roger.keays <> wrote:
> Does OpenJPA have any tricks we could use to get the persistence unit name
> which was used to create an EntityManager{Factory}?
> Cheers,
> Roger
> --
> View this message in context:
> Sent from the OpenJPA Users mailing list archive at

View raw message