import javax.annotation.Generated;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(Role.class)
public abstract class Role_ extends DomainBase_ {
public static volatile SingularAttribute<Role, String> roleName;
public static volatile ListAttribute<Role, Resource> resources;
public static volatile SingularAttribute<Role, String> comment;
public static volatile SingularAttribute<Role, String> id;
public static volatile ListAttribute<Role, User> users;
}
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name = "role")
public class Role extends DomainBase {
@Id
private String id;
@Column(columnDefinition="varchar(255) NOT NULL COMMENT '角色名'")
private String roleName;
@Column(columnDefinition="varchar(255) COMMENT '备注'")
private String comment;
@ElementCollection
@CollectionTable(name="resource",joinColumns=@JoinColumn(name="roleId"))
private List<Resource> resources=new ArrayList<>();
@ManyToMany(mappedBy="roles")
private List<User> users =new ArrayList<>();
}
这两个类有什么区别,@StaticMetamodel是怎么用的
这是JPA Criteria API的一部分
JPA Criteria API 是JPA中用于构建OOP风格的,较为灵活的SQL的一部分.其中包含
Metamodel API
,该API用于对Entity进行建模,JPA Criteria API有两种使用方式@StaticMetamodel(Role.class)
注解表明Role_
是Role
的Metamodel.也就是说在构建Criteria查询的时候如下的语句来指定where条件参考 Java EE 8 Tutorial by Oracle / Using the Metamodel API to Model Entity Classes
https://javaee.github.io/tuto...