package com.huigou.topsun.config;

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

/**
 * JPAUtils 用于管理 JPA EntityManager 创建工厂
 *
 * @author qinzhenguan
 * @create 2023/11/28 08:58
 **/
public class JPAUtils {
    
    public static EntityManagerFactory emf = createEntityManagerFactory();

    private static EntityManagerFactory createEntityManagerFactory() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("mysql-jpa");
        return emf;
    }

    public static EntityManager getEntityManger(){
        EntityManager entityManager = emf.createEntityManager();
        return entityManager;
    }

}