What does an underscore concatenated to a class name mean?

前端 未结 2 879
深忆病人
深忆病人 2021-01-31 15:25

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

EntityManager em = ...
CriteriaBuilder qb = em.getCriteriaBuil         


        
相关标签:
2条回答
  • 2021-01-31 15:46

    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.

    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.

    0 讨论(0)
  • 2021-01-31 15:53

    I found this way to declare the metamodel in this article.

    /**
     * A  meta model class used to create type safe queries from person
     * information.
     * @author Petri Kainulainen
     */
    @StaticMetamodel(Person.class)
    public class Person_ {
        public static volatile SingularAttribute<Person, String> lastName;
    }
    
    0 讨论(0)
提交回复
热议问题