I created a project with Swing and JPA and it is working fine, now I want to remove the file persistence.xml
and create a class to work on it. I'm researching some way to do this and found in the documentation an example of how to here . But I am not able to make it work, every time I run the project it returns the error: Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named iguanaauto
.
How to solve this problem?
I'm trying like this.
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;
}
}