Hibernate 被拆分为 org.hibernate.orm 组下的多个模块/工件。主体工件被命名为 hibernate-core。
本指南使用 6.6.0.Final 作为演示的 Hibernate 版本。如果有需要,确保将此版本更改为您要使用的版本。
我们可以使用 Gradle
dependencies {
implementation "org.hibernate.orm:hibernate-core:6.6.0.Final"
}
或 Maven
1.1. Hibernate ORM 模块
声明对该工件的依赖关系,如前所述,Hibernate ORM 被拆分为多个模块,目的是根据正在使用的功能或未使用功能来隔离传递性依赖项。
表 1. 面向 API 的模块
hibernate-core
核心对象/关系映射引擎
hibernate-envers
实体版本控制和审计
hibernate-spatial
使用 GeoLatte 支持空间/GIS 数据类型
hibernate-jpamodelgen
生成 JPA 兼容元模型的注释处理器,以及可选的 Hibernate 附加功能
hibernate-vector
支持数学向量类型和函数,这些对于 AI/ML 主题(例如向量相似性搜索和检索增强生成 (RAG))很有用
表 2. 面向集成的模块
hibernate-agroal
支持 Agroal 连接池
hibernate-c3p0
支持 C3P0 连接池
hibernate-hikaricp
支持 HikariCP 连接池
hibernate-vibur
支持 Vibur DBCP 连接池
hibernate-proxool
支持 Proxool 连接池
hibernate-ucp
支持 Universal Connection Pool 连接池
hibernate-jcache
与 JCache 的集成,允许将任何兼容的实现用作二级缓存提供程序
hibernate-graalvm
实验性扩展,使其可以更轻松地将应用程序编译为 GraalVM 原生映像
hibernate-micrometer
与 Micrometer 指标集成
hibernate-community-dialects
社区支持的其他 SQL 方言
表 3. 面向测试的模块
hibernate-testing
用于测试 Hibernate ORM 功能的一系列 JUnit 扩展
1.2. 平台/BOM
Hibernate 还提供了一个平台(Maven 术语中的 BOM)模块,可用于将 Hibernate 模块的版本与其实现的版本保持一致。平台制品命名为 hibernate-platform。
在 Gradle 中应用该平台
dependencies {
implementation platform "org.hibernate.orm:hibernate-platform:6.6.0.Final"
// use the versions from the platform
implementation "org.hibernate.orm:hibernate-core"
implementation "jakarta.transaction:jakarta.transaction-api"
}
请参阅 Gradle 文档,以了解应用平台的功能。
在 Maven 中应用平台 (BOM)
1.3. 示例源代码
本教程中提到的捆绑示例可从 此处 下载。
或者,还可以从 Github 获取示例源代码