Is it possible to create a container-managed EntityManager via a specific EntityManagerFactory

85 Views Asked by At

I'd like to use the container-managed EntityManager of JPA, but want it to be created from one specific EntityManagerFactory, is it possible to do that? Thanks

1

There are 1 best solutions below

0
dincer.unal On

I think you can use use a container-managed EntityManager of JPA. Maybe you can do this by specifying the persistence unit name when obtaining the EntityManager instance

@PersistenceUnit(unitName = "myPersistenceUnit")
private EntityManagerFactory entityManagerFactory;

public void someMethod() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    // Use the entityManager instance to perform JPA operations
    entityManager.close();
}