构建系统集成
识别构建系统
一些 Hibernate 项目使用 Maven,另一些使用 Gradle。在您从 GitHub 中检出项目后,检查源代码根目录中是否存在 pom.xml
文件:这意味着它是一个 Maven 项目。如果存在 build.gradle
文件,则需要使用 Gradle 构建它。
Gradle
一般来说,IntelliJ IDEA 对导入 Gradle 项目的支持应该是导入项目的首选方式。14.1 版本中对该功能的支持比以前的版本好得多。
根据我的 (Steve Ebersole) 经验,IntelliJ 12.1 是 Gradle 导入工作所需的绝对最低限度。每个 Hibernate 项目及其分支都应识别 IntelliJ、JDK 等的任何特定要求。通常来说,我发现使用 Java 8 运行 IntelliJ 14.1 的体验最好。 |
请注意,IntelliJ IDEA 12 或 13 中的自动导入似乎在 Mac OS X (mavericks) 上存在问题。以下是一组解决方法
-
编辑
/Applications/IntelliJ\ IDEA\ 13.app/Contents/Info.plist
,查找JVMSession
并将其更改为1.7*
;这将使 IntelliJ IDEA 本身在 JDK 7 上运行 - 请注意,在撰写本文时,它仍然没有解决第二个 gradle 导入问题,因此可能没有必要。 -
从命令行运行
./gradlew idea
并使用 IntelliJ IDEA 打开项目。请注意,您需要添加生成的源文件夹 (apt、antlr 等)。有关更多信息,请参见“注解处理器”部分。
代码风格
从我们的 GitHub 存储库下载设置
-
对于 Hibernate ORM:
hibernate_orm.xml
. -
对于 Hibernate Search、Validator、OGM:
intellij-14/hibernate_noorm.xmlhibernate-code-templates-search.xml
.
权威的代码风格由与项目相关的 CheckStyle 检查文件定义;在推送之前,请务必根据这些检查文件进行检查。
代码模板
将正确的版权/许可证标题自动应用于新创建文件的最佳方法是利用版权插件(现在是捆绑插件)。
在“版权”配置(“设置”→“版权”)中为要处理的每个 Hibernate 项目设置配置文件,然后选择一个用于 IntelliJ IDEA 项目的配置文件。
请注意,如果通过“其他设置”→“新项目的设置”→“版权”定义配置文件,则可以一次性定义所有配置文件:它们将在每个新的 IntelliJ IDEA 项目中自动可用。
以下是每个项目的标准许可证标题
-
Hibernate ORM
/* * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <https://gnu.ac.cn/licenses/lgpl-2.1.html>. */
-
Hibernate Search
/* * Hibernate Search, full-text search for your domain model * * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or <https://gnu.ac.cn/licenses/lgpl-2.1.html>. */
-
Hibernate Validator
/* * Hibernate Validator, declare and validate application constraints * * License: Apache License, Version 2.0 * See the license.txt file in the root directory or <https://apache.ac.cn/licenses/LICENSE-2.0>. */
-
Hibernate OGM
/* * Hibernate OGM, Domain model persistence for NoSQL datastores * * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or <https://gnu.ac.cn/licenses/lgpl-2.1.html>. */
调试
此信息与 IntelliJ IDEA 版本 9 相关。 |
通过 Hibernate 源代码进行调试的一个重要方面是确保仅仅调试行为不会强制代理初始化,仅仅是为了让调试器能够“显示”它们。在 IntelliJ IDEA 中,可以通过所谓的“数据类型渲染器”和“数据视图”轻松配置这一点。
要访问此配置,请打开您的设置(Ctrl+Alt+S),然后转到“IDE 设置”→“调试器”。展开“调试器”,您将找到“数据类型渲染器”和“数据视图”。
-
“数据视图”是通用配置。在这里,您一定希望禁用“启用 toString() 对象视图”。一般来说,禁用任何会导致调试器强制代理初始化的设置。
-
“数据类型渲染器”。我们需要定义 2 个特定类型的渲染器
-
实体代理渲染器
-
FQN:
org.hibernate.proxy.HibernateProxy
-
渲染:使用表达式 →
((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().isUninitialized() ? ( ((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().getEntityName()"@"+System.identityHashCode(this)"[proxy;id="((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().getIdentifier()"]" ) : this.toString()
-
展开:默认;如果用户尝试展开节点,这将强制代理初始化(如果尚未初始化)。
-
-
集合渲染器
-
FQN:
org.hibernate.collection.spi.AbstractPersistentCollection
-
渲染:使用表达式 →
((org.hibernate.collection.spi.AbstractPersistentCollection)this).wasInitialized() ? this.toString() : ( ((org.hibernate.collection.spi.AbstractPersistentCollection )this).getClass().getName()"@" System.identityHashCode(this)+" [uninitialized]" )
-
展开:默认;同样,如果用户尝试展开节点,这将强制集合初始化(如果尚未初始化)。
-
-
Hibernate ORM 中的注解处理器
这仅适用于 Hibernate ORM。 |
目前建议在 IntelliJ IDEA 中显式禁用注解处理器。从项目设置“Java 编译器”中,确保
-
“-proc:none”用作 javac 的选项
-
增加最大堆大小
然后在模块设置中
-
对于 hibernate-core 模块,添加这些源文件夹
-
target/generated-src/jaxb/main
-
target/generated-src/logging/main
-
target/generated-src/antlr/main
-
-
对于 hibernate-entitymanager,添加
-
target/generated-src/jpamodelgen/test
-
超越
如果您想为 Hibernate 项目做出贡献,请从这里开始。