Criei um projeto com Swing e JPA e está funcionando bem, agora quero retirar o arquivo persistence.xml
e criar uma classe para que trabalhe no lugar dele. Estou pesquisando alguma maneira de fazer isso e encontrei nas documentações um exemplo de como fazer aqui. Mas nao estou conseguindo fazer funcionar, sempre que executo o projeto retorna o erro: Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named iguanaauto
.
Como resolver esse problema ?
Estou tentando assim.
public class JPAUtils {
private static EntityManagerFactory emf;
/** retorna o entitymanager */
public static EntityManager getEntityManager(){
//emf = Persistence.createEntityManagerFactory("iguanaauto");
EntityManager em = getEntityManagerFactory().createEntityManager();
return em;
}
private static EntityManagerFactory getEntityManagerFactory(){
if(emf == null){
Map<String, String> properties = new HashMap<String, String>();
properties.put("javax.persistence.provider", "org.eclipse.persistence.jpa.PersistenceProvider");
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
properties.put("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/iguanaauto_db?createDatabaseIfNotExist=true");
properties.put("javax.persistence.jdbc.user", "root");
properties.put("javax.persistence.jdbc.password", "");
properties.put("eclipselink.ddl-generation", "create-or-extend-tables");
properties.put("eclipselink.ddl-generation.output-mode", "database");
properties.put("eclipselink.logging.level", "FINE");
emf = Persistence.createEntityManagerFactory("iguanaauto", properties);
}
return emf;
}
}