[Solved] Illegal attempt to dereference path source [null.categoryList] of basic type

[Resolved] Illegal attempt to dereference path source [null.categoryList] of basic type

This issue may happen for various use cases, I have explianed my usecase with the explantion, hope it helps someone.

Issue code:

Expression catInExp = couponRoot.get("categoryList").get("categoryName");
Predicate categoryInPredicate = catInExp.in(tempCategoryNamesSelected);
allPredicates.add(categoryInPredicate);

Code Fixed:

root.get() is changed to root.join()

Expression catInExp = couponRoot.join("categoryList").get("categoryName");
Predicate categoryInPredicate = catInExp.in(tempCategoryNamesSelected);
allPredicates.add(categoryInPredicate);

My Coupon Model:

@Entity
public class Coupon implements Serializable{

@ManyToMany
private Set categoryList;
}

and my Category Model is:

@Entity
public class Category implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="category_id")
private Long categoryId;

private String categoryName;

@ManyToMany
private Set coupon;
}

Now in the issue code, I have tried to get the categoryName of the categoryList(Category Model) entity using .get() method, which is actually the issue because we need to join with categoryList then we need to get the categoryName field as our entity maps the same way.

Hope this helps!

One comment

Leave a Reply