How to resolve JPA Hibernate error

Asked

Viewed 2,921 times

2

You can help me with this mistake?

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named bsewebservicePU
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at br.com.brbsemanager.util.HibernateSchemaGeneration.main(HibernateSchemaGeneration.java:23)

I’ve done everything in the project to try to run, but nothing worked.

Follow my persistence.xml and the project folders tree:

<persistence-unit name="bsewebservicePU" transaction-type ="RESOURCE_LOCAL">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>br.com.bsemanager.domain.Entidades.Cliente</class>
    <class>br.com.bsemanager.domain.Entidades.Emprestimo</class>
    <class>br.com.bsemanager.domain.Entidades.Endereco</class>
    <class>br.com.bsemanager.domain.Entidades.Operador</class>

    <properties>
        <property name="javax.persistence.jdbc.url" 
        value="jdbc:mysql://localhost:3306/bsemanager"/>

        <property name="javax.persistence.jdbc.user" 
        value="root"/>

        <property name="javax.persistence.jdbc.password" 
        value="root"/>

        <property name="javax.persistence.jdbc.driver" 
        value="com.mysql.jdbc.Driver"/>

        <property name="hibernate.dialect" 
        value="org.hibernate.dialect.MySQL5Dialect"/>

        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
    </properties>
</persistence-unit>

Estrutura do projeto

This is the class I’m using to generate the tables in the database and it’s when you give the error:

public class HibernateSchemaGeneration {

    public static void main(String[] args) throws MappingException, IOException {


        Persistence.createEntityManagerFactory("bsewebservicePU");
    }
}
  • The persistence.xml is inside the folder src/main/java/META-INF?

  • What’s in your class br.com.brbsemanager.util.HibernateSchemaGeneration?

  • Your persistence.xml needs to be inside the folder src/main/resources/META-INF, currently, it seems, is in src/main/java/META-INF.

  • I moved the Meta-inf folder to src/main/Resources/META-INF and added it to classpath, but the error continues. Before it was in src/main/java/.

  • Victor I posted the content of the class in the question. Thank you.

  • Did you notice that almost all packages contain errors? I think there may be some lib missing, how do you tell us which error they say ?

  • Dilneicunha errors were pq in the classes had the Notation @Component of spring that I am no longer using. I already removed it and the errors, only errors remained in the entities, because the project is connected with the bank conection and the eclipse is seeing that the tables do not exist yet. The rest is without error.

  • right, but what it says in this error of the entities?

  • Dilnei, the error is in the Annotation @Entity and says: Table XXX can not be resolved.

  • right, if the import is correct, this is a validation bug, if you disable the validations the error is missing, the application is already compiling normally? run from the same above mentioned persistence error ?

  • Dilnei disabled the validation and the eclipse error in Annotation is gone, but even so when I run this class I posted the error remains. I am running as Javaaplication and not on the webserver.

  • blz Manu, then this almost there, by what I saw you just created the factory and did nothing else, not even returned to an Entitymanagerfactory emf; after creating the factory do: Entitymanager em = emf.createEntityManager(); then it is give new in the popular obejto and do in.persist(object) do not forget that you have to open the trasaction to save, when working standalone need to do everything at hand.

Show 7 more comments

2 answers

2

Hi, you are using the Eclipselink 2.5.2 library in your classpath, but in your persistence.xml it says that your implementation is Hibernate...

Ex:

<provider>org.hibernate.ejb.HibernatePersistence</provider>

Answer: you must exchange the Eclipselink 2.5.2 library for one of Hibernate in your classpath. Access and download a library with a version compatible with your application http://hibernate.org/

ps: the errors flagged in your project, must be the incompatibility of Eclipselink library Imports.

1

If the Bundle and jars in use are the version 5.2.2 of Hibernate, I think it might be worth my answer below that I published in another question... I’ll just paste below... But basically, in this new version, there is no class org.hibernate.ejb.Hibernatepersistence, I do not know if it was deprecated or if they simply withdrew. I had to use the class org.hibernate.jpa.Hibernatepersistenceprovider as Provider in persistence.xml and, for me at least, it worked..

The class org.hibernate.ejb.Hibernatepersistence does not exist in the Hibernate-release-5.2.2.Final. zip Bundle file. That’s Why the Provider can’t be found, because the class can’t (at the project library jars). Instead, I used the class org.hibernate.jpa.Hibernatepersistenceprovider, which CAN be found at Hibernate-core-5.2.2.Final. jar (that comes with Hibernate-release-5.2.2.Final.zip Bundle), by Changing the Provider at persistence.xml to <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>. Doing so, it worked fine! Hope the problem is only this.

Browser other questions tagged

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