There are several ways to use an EntityManagerFactory.

One is indeed Persistence.createEntityManagerFactory but you need to set
the ContextClassLoader to a classloader that can see the persistence
provider as well as the database drivers. This is more a workaround than a
good solution.

Another option is to use Aries JPA. It creates the EMF from you
persistence.xml and offers it as an OSGi service which you can then refer
to.
See
https://github.com/apache/aries-jpa/tree/master/examples

Christian

Reply via email to