0

I wrote my first hibernate project exactly as same as my teacher did but I got this exception :

> Exception in thread "main" java.lang.ExceptionInInitializerError
> Caused by: javax.persistence.PersistenceException: No Persistence
> provider for EntityManager named Sharif: Provider named
> org.hibernate.jpa.HibernatePersistenceProvider threw unexpected
> exception at create EntityManagerFactory:  java.lang.NoSuchMethodError
> java.lang.NoSuchMethodError:
> javax.persistence.Table.indexes()[Ljavax/persistence/Index;

and I wrote persistence-unit name in persistence.xml file

<persistence-unit name="Sharif" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

and I also use Entity annotation in my entity class (Person) I check almost all Question that relates to my problem but I can't solve it. project dependencies:
enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
saba safavi
  • 160
  • 7
  • 20
  • Possible duplicate of [No Persistence provider for EntityManager named](https://stackoverflow.com/questions/1158159/no-persistence-provider-for-entitymanager-named) – Jakob Aug 12 '17 at 16:13
  • The error message says `Provider named > org.hibernate.jpa.HibernatePersistenceProvider threw unexpected`; this leads me to believe that the provider was correctly specified, and the problem is somewhere else. My bet is that you have conflicting versions of hibernate/jpa providers on your classpath. Can you show the list of all your project dependencies? – Andrei Aug 12 '17 at 16:13
  • @Jakob, it's not a duplicate of the issue you mention. At most, I think it's a duplicate/slight variation of this one: https://stackoverflow.com/questions/20734540/nosuchmethoderror-in-javax-persistence-table-indexesljavax-persistence-index If you look at the error message you'll see that it correctly detected the specified provider; the message is a bit misleading. – Andrei Aug 12 '17 at 16:15
  • @Andrei I've just started Hibernate from today I don't know where I can find my project dependencies.I already heard about dependencies in maven project is it right? my project isn't maven – saba safavi Aug 12 '17 at 16:52
  • Sorry, that's why I've said "dependencies" and not "Maven dependencies". Typically any project has a set of dependencies; it is just their format that differs. What are you using to build your project? Just an IDE like Eclipse/IntelliJ/Netbeans? Are you also using an external tool such as Gradle or Ant, or anything else? – Andrei Aug 12 '17 at 16:54
  • I use IntelliJ. no, I don't use an external tool. – saba safavi Aug 12 '17 at 16:59
  • I haven't used IntelliJ in a while, but maybe this can help you see the list of dependencies : https://www.jetbrains.com/help/idea/dependencies-tab.html Then could you edit your question with the list of dependencies? Maybe we can see what's wrong this way. – Andrei Aug 12 '17 at 18:23
  • @Andrei is this what you want to see? – saba safavi Aug 12 '17 at 18:47
  • almost. Does the `lib` item have any children? – Andrei Aug 12 '17 at 18:53
  • it's Hibernate libs and no children in dependencies – saba safavi Aug 12 '17 at 19:01
  • try to add persistence-api jar – vineeth Aug 14 '17 at 03:46

1 Answers1

1

I created a new project and copy all my code in it. I guess my problem happened because of existing 2 version of hibernate-core.jar, this file hibernate-core-5.2.10.Final.jar and this hibernate-core-5.2.1.Final.jar. I deleted extra jar files and copied new lib folder into the new project and it runs successfully.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
saba safavi
  • 160
  • 7
  • 20