EclipseLink 2.7.0 and JPA API 2.2.0 - signature mismatch

前端 未结 10 1556
滥情空心
滥情空心 2020-12-03 04:31

When running a project built by maven with the following dependencies:

        
            org.eclipse.persistence

        
相关标签:
10条回答
  • 2020-12-03 05:01

    Obinna's answer is correct; I guess that there was an issue with eclipselink 2.7.x –as George indicated. I had a similar issue when upgrading eclipselink, but it was just wrong artefacts. The initially described issue seems to be a result of externally referencing javax.persistence level - it is definitely not necessary.

    Proper maven configuration can be found in eclipselink wiki: https://wiki.eclipse.org/EclipseLink/Maven

    0 讨论(0)
  • 2020-12-03 05:06

    I'm using gradle in my project build and to solve the OP's problem, which I had as well, I finally used the following working setup.

    dependencies {
    
        testImplementation(group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.7.4') {
            exclude group: 'javax.validation', module: 'validation-api'
            exclude group: 'org.eclipse.persistence', module: 'javax.persistence'
            exclude group: 'org.eclipse.persistence', module: 'commonj.sdo'
            exclude group: 'org.eclipse.persistence', module: 'jakarta.persistence'
        }
    
        testImplementation(group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version: '2.7.4') {
            exclude group: 'org.eclipse.persistence', module: 'jakarta.persistence'
        }
    
    }
    

    Instead of "testImplementation" you can of course use any dependency type you want or need.

    After reading Sergey's comment I've improved this by just using:

    dependencies {
        testImplementation group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version: '2.7.4'
    }
    

    I think the last one is the best solution.

    0 讨论(0)
  • 2020-12-03 05:09

    This strange situation still seems to exist, in my case not using Maven, just trying to get a simple JPA example to run (and it is really frustrating if you need hours just to achieve that).

    With 2.7.4 from January, this error occurs if you put the eclipselink.jar and jakarta.persistence_2.2.2.jar from the zip on the classpath.

    In the end solution was to change order on the classpath: first the jakarta-persistence and only after that the eclipselink-jar. So all javax.persistence classes are taken from jakarta-jar and not partly of the eclipselink-jar (if included there).

    So I really wonder various things.

    The eclipselink package should be all-in-one? But it is not. Some javax.persistence classes are contained. Others not - basic classes to be used in JPA code like EntityManager. Of course, together with the jakarta-jar included in the zip it is complete - but you may not use the two jars together with the "wrong" order on the classpath!? I really consider this a bug - or at least there should be a HUGE hint about this in the package then.

    What is the org.eclipse.persistence.jpa-2.7.4.jar from Maven that is suggested here? It does not have the problems of the eclipselink.jar yes, not this error message. But then it also just seems not to include the Eclipselink JPA implementation, at least running with it I got error that persistence-unit referenced in code does not exist (same persistence.xml working with eclipselink.jar).

    Strange situation.

    0 讨论(0)
  • 2020-12-03 05:10

    To fix this issue, put in the correct JPA 2.2 compliant dependency for EclipseLink 2.7.x, in your maven pom file, as:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.7.1</version>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题