为什么在 Java 应用程序中使用 JPA Hibernate 元模型 类?
Why JPA Hibernate Metamodel classes are used in Java app?
我开发了一个 Java 应用程序,有几个元模型 类 例如“公司_”。但是,这些在目标文件夹中,我想知道为什么我们要使用它们,因为其他文件,例如“公司”也将在目标文件夹中构建和生成。那么,在 Java app.
中使用 JPA Hibernate Metamodel 类 的目的是什么?
如有任何解释,我们将不胜感激。
Then, what is the purposes using JPA Hibernate Metamodel classes in a Java app.
为什么我们需要元模型类你问?
它们是一个内部细节,可以实现 criteria queries 的类型安全。它们是达到目的的手段。这就是标准查询的类型安全。如果这可以以更简单的方式实现,没有这些额外的 类 ,那么这样做将是理想的。更少 类 -> 使用更少的 RAM -> 更少的类加载 -> 更少的启动时间。
具体来说,这是这样做的动机...
When you write a criteria query or create a dynamic entity graph, you need to reference the entity classes and their attributes. The quickest and easiest way is to provide the required names as Strings. But this has several drawbacks, e.g. you have to remember or look-up all the names of the entity attributes when you write the query. But it will also cause even greater issues at later phases of the project if you have to refactor your entities and change the names of some attributes. In that case, you have to use the search function of your IDE and try to find all Strings that reference the changed attributes. This is a tedious and error-prone activity which will easily take up the most time of the refactoring.
您可以在此处查找更多 details。
如果您想深入了解为什么选择这样的实现来实现此目标,您可以查看原文 Java Specification Request 并了解所有详细信息。
这是否解决了您的问题?在评论中让我知道。
我开发了一个 Java 应用程序,有几个元模型 类 例如“公司_”。但是,这些在目标文件夹中,我想知道为什么我们要使用它们,因为其他文件,例如“公司”也将在目标文件夹中构建和生成。那么,在 Java app.
中使用 JPA Hibernate Metamodel 类 的目的是什么?如有任何解释,我们将不胜感激。
Then, what is the purposes using JPA Hibernate Metamodel classes in a Java app.
为什么我们需要元模型类你问?
它们是一个内部细节,可以实现 criteria queries 的类型安全。它们是达到目的的手段。这就是标准查询的类型安全。如果这可以以更简单的方式实现,没有这些额外的 类 ,那么这样做将是理想的。更少 类 -> 使用更少的 RAM -> 更少的类加载 -> 更少的启动时间。
具体来说,这是这样做的动机...
When you write a criteria query or create a dynamic entity graph, you need to reference the entity classes and their attributes. The quickest and easiest way is to provide the required names as Strings. But this has several drawbacks, e.g. you have to remember or look-up all the names of the entity attributes when you write the query. But it will also cause even greater issues at later phases of the project if you have to refactor your entities and change the names of some attributes. In that case, you have to use the search function of your IDE and try to find all Strings that reference the changed attributes. This is a tedious and error-prone activity which will easily take up the most time of the refactoring.
您可以在此处查找更多 details。
如果您想深入了解为什么选择这样的实现来实现此目标,您可以查看原文 Java Specification Request 并了解所有详细信息。
这是否解决了您的问题?在评论中让我知道。