3

i searched for this problem such

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

but the answer didnt work for me

i am using jdk 1.7 , i set the compiler to 1.7.0_79 which meant to be java 7 but when i run i still getting the error , i set the project byte code version to 1.7 but the same message

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/hibernate/jpa/HibernatePersistenceProvider : Unsupported major.minor version 52.0

this exception happens when try to load the persistence.xml on this line

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

and in the java code on this line

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("sample");
Community
  • 1
  • 1
user1610308
  • 161
  • 3
  • 11
  • the only way is to use java 8 – user1610308 Oct 18 '16 at 08:59
  • 1
    Not sure how the link cannot help you. Have you checked here? http://hibernate.org/orm/documentation/getting-started/ If you are using Hibernate 5.2 or later, you need to use JDK8. The link you quoted DOES explain why – Adrian Shum Jan 17 '17 at 02:18

4 Answers4

5

I had encountered the same issue while working on a project with Hibernate: Caused by: java.lang.UnsupportedClassVersionError: org/hibernate/jpa/HibernatePersistenceProvider : Unsupported major.minor version 52.0.

Updating IntelliJ and Maven project settings (as noted here and here) to use the same Java version for compiling and running didn't fix the issue.

As noted by Adrian Shum before, if you want to use Java 7 you have to check Hibernate-related libraries because Hibernate 5.2 and later versions require at least Java 1.8 (Hibernate System Requirements).

In my case, downgrading the library version inside the POM file solved the problem, by changing

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.6.Final</version>
</dependency>

into

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.1.4.Final</version>
</dependency>
Community
  • 1
  • 1
aUserHimself
  • 1,589
  • 2
  • 17
  • 26
1

I had the same issue, the way I could compile it using JDK7 was to add hibernate-jpamodelgen into my pom.xml.

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <version>5.x.x.Final</version>
</dependency>

Adding this should resolve the issue, just select the version you were working on

0

" Unsupported major.minor version " usually appears because you are compiling the java program with a bigger version of java than the one you're trying to run it with.

So in your case you compiled your application with java 7, but you probably are trying to run it with java 6 or smaller.

Change the version of java with which you run your application to match the one that you are compiling with (7 in your case).

Catalin Florea
  • 227
  • 3
  • 12
0

As hibernate core version 5.2 and upper not support with JDK 1.7 . So Please change maven dependency into 5.1.x and lower version for JDK 1.7. But in all lower version of hibernate core have missing all class of "org.hibernate.jpa" package.

If you need hibernate persistence provider then get exception for not class found. So that you should add a new dependency.

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.4.Final</version>
</dependency>
  • After add this dependency if you still get not class found exception then add @EnableJpaRepositories for JPA repositories.