Search code examples
javahibernateintellij-ideajdk1.7

HibernatePersistenceProvider : Unsupported major.minor version 52.0 intellij


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");

Solution

  • 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>