Problem with table generation (tutorial algaworks)

Asked

Viewed 177 times

1

I’m reading the book Java EE 7, with JSF, primefaces and CDI. I got to 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");
    }
}

By running this class as a Javase program I am 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)

Up until posted a question on Stackoverflow in English asking about it. There I also posted all the configuration of my application.

Then one of the forum participants asked me why I’m running a Javase application within a Javaee application. I also suspected that there would be no way this class would get pom.xml and Hibernate settings. In the book it does not make clear how to run that class (in the case of the Book the Create Tables class, in my case the Main class). I assumed that it would be run as normal Javase application, since it starts from 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 a mistake in the name of my Persistence United. After this problem and other mapping problems the generation of tables using the main class ran smoothly.

  • Solved the problem?

  • @Weslleytavares, yes, it was a simple typo in the name of my Persistence Unit.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.