I'm reading the Java EE 7 book, with JSF, primefaces and CDI. I got the configuration part of hibernate, but I'm having problems. I configured my application in a J2EE environment, with JSF and etc and using WildFly as Server. After configuring the persistence.xml file and creating the mapping of my classes, I'm having trouble trying to generate the database, using that class with the main method:
import javax.persistence.Persistence;
public class CriaTabelas {
public static void main(String[] args) {
Persistence.createEntityManagerFactory("FinanceiroPU");
}
}
When running this class as a JavaSE program I'm getting the following error:
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named OCPQuizPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at br.com.alexpfx.ocpquiz.faces.domain.Main.main(Main.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Until posted a question in StackOverflow in English asking about it. There I also posted the whole configuration of my application.
Then one of the forum participants asked me why I'm running a JavaSE application inside a JavaEE application. I also suspected that there would be no way for this class to get the settings of pom.xml and hibernate. In the book does not make it clear how to run that class (in the case of the Book the class CreateTables, in my case the class Main). I assumed that it would be round as normal JavaSE application, since it part of a Main method ... But apparently I have to change the configuration scheme or even create a Java SE project just to generate the database.
EDIT
Problem solved: In my case it was an error in the name of my Persistence United. After this problem and other mapping problems generating tables using the main class ran smoothly.