ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

如何将Hibernate从版本4.3升级到5.2以迁移到JDK 10?[英] How to upgrade Hibernate from version 4.3 to 5.2 for migratio

2022-06-04 09:01:28  阅读:199  来源: 互联网

标签:10 5.2 Hibernate 4.3 JDK hibernate


如何将Hibernate从版本4.3升级到5.2以迁移到JDK 10?[英] How to upgrade Hibernate from version 4.3 to 5.2 for migration to JDK 10?   本文介绍了如何将Hibernate从版本4.3升级到5.2以迁移到JDK 10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于JDK8 Oracle宣布不再支持,因此我需要将当前的JDK升级到JDK10

研究后,还需要当前的hibernatehibernate 4升级到hibernate 5,以便在JDK 10.上运行

但是,有一些与休眠相关的库,如果是的话,我还应该升级哪个版本合适?这是我当前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>

 

推荐答案

仅谈论依赖项,从Hibernate 4.3.x 升级到> = 5.2.x 的过程很简单.非常简单.最新的> = 5.2.x 版本非常可靠,并且已经社区进行了测试.现在已经有一段时间了.较新的版本> = 5.3.x 已于2018年5月发布.

您可以通过以下代码片段在pom.xml中实现迁移:

<properties>
    <hibernate.version>5.2.17.Final</hibernate.version>
    <hibernate.validator.version>6.0.10.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 5.3.x

Just replace one property value to read:

<hibernate.version>5.3.1.Final</hibernate.version>

所有其他相关的传递依赖项都通过上述工件自动拉入.

请注意 

原始的pom.xml代码段所使用的hibernate-entitymanager-...jar在Hibernate 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文件,以便

  1. 您设置了:<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
  2. ,并将标头定义为符合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">

要符合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">

 

 

更多评论

从理论上讲,所有重要的依赖关系都应使用上述代码片段绘制到您的项目中.但是,实际上,您(很可能)会在现有项目代码的 compile  runtime 上遇到一些重大更改.通过查看以下官方的迁移指南,可以解决许多问题:

Further remarks

In theory, all important dependencies should be drawn into your project with the above snippets. However, in practice, you will (most likely) encounter some breaking changes at compile or runtime with your existing project code. Many of these can be resolved by checking the official migration guides here:

  • 版本 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/迁移/ 可以跳过,除非您使用BLOB和Oracle的DBMS或使用Hibernate的模式导出工具

版本 5.1.x-> 5.2.x :

https://github.com/hibernate/hibernate -orm/wiki/迁移指南--- 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环境中应该可以正常工作.

希望有帮助.

 如何将Hibernate从版本4.3升级到5.2以迁移到JDK 10? - IT屋-程序员软件开发技术分享社区 (it1352.com)

标签:10,5.2,Hibernate,4.3,JDK,hibernate
来源: https://www.cnblogs.com/roak/p/16341243.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有