Cor*_*wok 2 hibernate jpa java-10 hibernate-5.x
由于JDK8 Oracle宣布不再支持,我需要将当前升级JDK到JDK10.
经过研究,目前hibernate还需要从 升级hibernate 4到hibernate 5,才能运行在JDK 10.
但是,有一些hibernate相关的库,我是否也应该升级,如果是,哪个版本适合?这是我当前的摘录pom.xml:
<properties>
<hibernate.version>4.3.11.Final</hibernate.version>
<java-version>1.7</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
仅就依赖而言,从 Hibernate 4.3.x升级到>= 5.2.x非常简单。最新的 >= 5.2.x版本非常可靠,并且已经由社区测试了很长一段时间。最新版本 >= 5.3.x已于 2020 年 11 月发布。
您可以pom.xml使用以下代码段实现迁移:
<properties>
<hibernate.version>5.2.18.Final</hibernate.version>
<hibernate.validator.version>6.0.21.Final</hibernate.validator.version>
<java-version>10</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
只需替换一个属性值即可读取:
<hibernate.version>5.3.20.Final</hibernate.version>
Run Code Online (Sandbox Code Playgroud)
所有其他相关的传递依赖项都通过上述工件自动引入。
记好
将hibernate-entitymanager-...jar其用于您的原始pom.xml片段不再处于休眠5.2.x.存在 与 JPA/EntityManager 相关的所有内容现在都包含在hibernate-core-...jar.
从6.0.10版本开始,该库完全支持 JDK10:
您现在可以使用 JDK 10 构建和使用 Hibernate Validator。
参考:http : //in.relation.to/2018/05/15/hibernate-validator-6010-final-out/
此外,检查persistence.xml项目中的每个文件,以便
你设置: <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
并将标头定义为符合 JPA 2.1:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
Run Code Online (Sandbox Code Playgroud)
或 3. 成为 JPA 2.2符合作为
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
Run Code Online (Sandbox Code Playgroud)
理论上,所有重要的依赖项都应该用上面的代码片段引入到你的项目中。但是,在实践中,您(很可能)会在编译或运行时遇到一些破坏性更改对现有项目代码。其中许多可以通过在此处查看官方迁移指南来解决:
版本4.3.x -> 5.0.x:
https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc在您的案例中非常推荐阅读(因为您从版本 4.3.x 开始)
版本5.0.x -> 5.1.x:
http://staging.hibernate.org/orm/documentation/5.1/migration/ 可以跳过,除非您使用 BLOB 和 Oracle 的 DBMS 或使用 Hibernate 的模式导出工具
版本5.1.x -> 5.2.x:
https://github.com/hibernate/hibernate-orm/wiki/Migration-Guide---5.2 包含了很多重要变化的信息,比如PK生成、LimitHandler等
版本5.2.x -> 5.3.x:
https://github.com/hibernate/hibernate-orm/wiki/Migration-Guide---5.3增加了完整的 JPA 2.2 支持,在 JDK8/9/10 环境中应该可以正常工作。
希望能帮助到你。
| 归档时间: |
|
| 查看次数: |
8195 次 |
| 最近记录: |