NullPointerException at org.hibernate.ejb.criteria.path.AbstractPathImpl.get [duplicate]

14    7 months ago

This works fine:

 public Predicate toPredicate(Root<Campaign> root,
    CriteriaQuery<?> query, CriteriaBuilder cb) {
    return root.get("campState").get("statusId").in(campStatus);

but I change to :

 return  root.get(Campaign_.campState).get(CampState_.campId).in(campStatus).

And it throws exception:

edit for: NullPointerException at org.hibernate.ejb.criteria.path.AbstractPathImpl.get

  public class Campaign_ {
  public static volatile SingularAttribute<Campaign, CampState> campState;
  public static volatile SingularAttribute<Campaign, Long> campId;

  public class CampState_ {
  public static volatile SingularAttribute<CampState, String> statusId;

  @ManyToOne(cascade = {CascadeType.REFRESH, CascadeType.MERGE})
  @JoinColumn(name = "camp_status")
  public CampState getCampState() {
    return campState;

  public void setCampState(CampState campState) {
    this.campState = campState;
Answers { 1 }
7 months ago

Given two queries operate to different attributes. Second query cannot be compiled, because CampState_ does not have attribute campId (Campaign_ does have such a attribute.

Query that is equivalent to first one with static metamodel is: