为什么 JPA 元模型中的所有字段都是空的?
Why are all fields null in JPA Metamodel?
我正在学习 JPA 标准和元模型。我找到了以下元模型示例:
@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;
}
此元模型的所有字段均为空。那么,谁能解释一下 JPA 提供程序将如何获取,例如,以下示例中的字段名称:
criteria.where(builder.equal( personRoot.get( Person_.age ), 50));
这些字段在运行时不为空,因为 JPA 实现将所有这些 public 静态字段设置为 non-null 值。
规范摘录(6.2.2 - Bootstrapping):
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.
我正在学习 JPA 标准和元模型。我找到了以下元模型示例:
@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;
}
此元模型的所有字段均为空。那么,谁能解释一下 JPA 提供程序将如何获取,例如,以下示例中的字段名称:
criteria.where(builder.equal( personRoot.get( Person_.age ), 50));
这些字段在运行时不为空,因为 JPA 实现将所有这些 public 静态字段设置为 non-null 值。
规范摘录(6.2.2 - Bootstrapping):
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.