[英]Why are all fields null in JPA Metamodel?
I am just learning JPA criteria and metamodels. 我只是在学习JPA标准和元模型。 I found the following example of a metamodel: 我发现以下元模型示例:
@StaticMetamodel( Person.class )
public class Person_ {
public static volatile SingularAttribute<Person, Long> id;
public static volatile SingularAttribute<Person, String> name;
public static volatile SingularAttribute<Person, Integer> age;
public static volatile SingularAttribute<Person, Address> address;
public static volatile SetAttribute<Person, Order> orders;
}
All fields of this metamodel are null. 此元模型的所有字段均为空。 So, could anyone explain how JPA provider will get, for example, field name in the following example: 因此,任何人都可以在以下示例中解释JPA提供程序如何获取字段名称:
criteria.where(builder.equal( personRoot.get( Person_.age ), 50));
The fields are not null at runtime, because the JPA implementation sets all those public static fields to non-null values. 这些字段在运行时不为null,因为JPA实现将所有这些公共静态字段设置为非null值。
Excerpt from the specifications (6.2.2 - Bootstrapping): 摘录自规范(6.2.2-自举):
When the entity manager factory for a persistence unit is created, it is the responsibility of the persistence provider to initialize the state of the metamodel classes of the persistence unit. 创建持久性单元的实体管理器工厂时,持久性提供者有责任初始化持久性单元的元模型类的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.