jpa 关联查询@JoinColumn name 和root.get("xx") 的区别

jpa  UserEntity实体类中
@OneToMany(cascade={ CascadeType.ALL }, fetch = FetchType.EAGER)
@JoinColumn(name = "user_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))

@JoinColumn(name = "user_id" 这个位置是数据库中字段的名称

 

services中
Specification specification = new Specification() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) 
Predicate  predicate = criteriaBuilder.equal(root.get("userid").as(String.class),'%'+phone1+'%');
predicateList.add(predicate);

root.get("phone1")  phone1是实体类属性名

你可能感兴趣的:(spring,jpa)