Creates or returns current EntityManagerFactory . - Java javax.persistence

Java examples for javax.persistence:EntityManager

Description

Creates or returns current EntityManagerFactory .

Demo Code


import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class Main{
    private static EntityManagerFactory entityManagerFactory;
    /**/*w ww .  jav  a  2s  .  c  o  m*/
     * Creates or returns current {@link EntityManagerFactory}.
     * @param persistenceUnitName Persistence unit name form persistence.xml.
     * @return Current {@link EntityManagerFactory}.
     */
    public static EntityManagerFactory entityManagerFactory(
            String persistenceUnitName) {
        if (entityManagerFactory == null) {
            JPAHelper.persistenceUnitName = persistenceUnitName;
            entityManagerFactory = Persistence
                    .createEntityManagerFactory(JPAHelper.persistenceUnitName);
        }
        return entityManagerFactory;
    }
}

Related Tutorials