仅谈到依赖关系,从 Hibernate 4.3.x升级到>= 5.2.x非常简单。最新的 >= 5.2.x版本非常可靠,并且已经被社区测试了很长一段时间。更新的版本 >= 5.3.x已于 2020 年 11 月发布。
您可以pom.xml
使用以下代码段实现迁移:
休眠 5.2.x
<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>
休眠 5.3.x
只需替换一个属性值即可:
<hibernate.version>5.3.20.Final</hibernate.version>
所有其他相关的传递依赖项都是通过上述工件自动引入的。
记好
Hibernate 5.2.x 中不再存在hibernate-entitymanager-...jar
原始代码片段使用的那个。pom.xml
与 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">
或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">
补充说明
理论上,所有重要的依赖项都应该使用上面的代码片段引入到您的项目中。但是,在实践中,您将(很可能)在编译或运行时使用现有项目代码遇到一些重大更改。其中许多问题可以通过在此处查看官方迁移指南来解决:
希望能帮助到你。