persistence-api-1.0.2,这个版本太低了,缺很多类

    1. <dependency>
    2. <groupId>javax.persistence</groupId>
    3. <artifactId>persistence-api</artifactId>
    4. <version>1.0.2</version>
    5. </dependency>

    javax.persistence-api-2.2,这个必须要jdk8+才能运行

    1. <dependency>
    2. <groupId>javax.persistence</groupId>
    3. <artifactId>javax.persistence-api</artifactId>
    4. <version>2.2</version>
    5. </dependency>

    最终选择hibernate-jpa-2.1-api,支持jdk1.6
    这个版本与javax.persistence-api-2.2相比基本相同
    只缺少TableGenerators和SequenceGenerators两个注解

    1. <dependency>
    2. <groupId>org.hibernate.javax.persistence</groupId>
    3. <artifactId>hibernate-jpa-2.1-api</artifactId>
    4. <version>1.0.2.Final</version>
    5. </dependency>

    由于groupId和artifactId不相同,需要添加exclusion才能避免冲突

    1. <dependency>
    2. <groupId>org.hibernate</groupId>
    3. <artifactId>hibernate-core</artifactId>
    4. <version>5.0.8.Final</version>
    5. <exclusions>
    6. <exclusion>
    7. <groupId>org.hibernate.javax.persistence</groupId>
    8. <artifactId>hibernate-jpa-2.1-api</artifactId>
    9. </exclusion>
    10. </exclusions>
    11. </dependency>
    12. <dependency>
    13. <groupId>tk.mybatis</groupId>
    14. <artifactId>mapper</artifactId>
    15. <version>3.3.8</version>
    16. <exclusions>
    17. <exclusion>
    18. <groupId>javax.persistence</groupId>
    19. <artifactId>persistence-api</artifactId>
    20. </exclusion>
    21. </exclusions>
    22. </dependency>