简体   繁体   中英

Why are all fields null in JPA Metamodel?

I am just learning JPA criteria and metamodels. 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:

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.

Excerpt from the specifications (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM