下划线连接到类名是什么意思? [英] What does an underscore concatenated to a class name mean?

查看:223
本文介绍了下划线连接到类名是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读JPA 2.0中的动态,类型安全查询文章偶然发现了这个例子:

I was reading the "Dynamic, typesafe queries in JPA 2.0" article and stumbled upon this example:

EntityManager em = ...
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Person> c = qb.createQuery(Person.class);
Root<Person> p = c.from(Person.class);
Predicate condition = qb.gt(p.get(Person_.age), 20);
//                                     ^^ --- this one
c.where(condition);
TypedQuery<Person> q = em.createQuery(c); 
List<Person> result = q.getResultList();

我想知道这里的下划线究竟是什么意思?

I was wondering, what exactly does the underscore here mean?

由于下划线是类名的有效部分,我不明白为什么可以在JPA中使用它。
我在我的代码中使用现有实体检查了这个,当然我的类无法解析为 ClassName _

Since an underscore it is a valid part of a classname I don't understand why this can be used in JPA. I checked this with an existing entity in my code and of course my class couldn't be resolved as ClassName_

推荐答案

这是元模型的持久性。这是你如何用Java键入安全的JPA查询。它允许查询静态检查您的查询,因为类 Bar _ 描述了您的JPA Bar 。在HQL中,您可以轻松输入错误的查询,直到它运行才知道它。

That is the metamodel for the persistance. It is how you can do type safe JPA queries in Java. It allows queries to staticly check your queries because classBar_ describes your JPA Bar. In HQL, you can easily mistype a query and not know it until it is run.

从技术上讲, _ 并不意味着什么,但它是JPA用来命名JPA持久模型类的元模型类的约定。 Model _ Model 的元模型,它提供了可查询字段及其类型的名称。

So technically, the _ does not mean anything, but it is the convention used by JPA to name a metamodel class of a JPA persistent model class. Model_ is the metamodel of Model, and it provides the names of the queryable fields and their types.

这篇关于下划线连接到类名是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆