Suppose we have the following class graph:
public final class Address {
private final String streetAddress
public String getStreetAddress() {
return streetAddress;
}
}
public final class House {
private Address address;
}
Now I want to query all the houses that match an specific street address using JPA Criteria API. I tried to do this but it did not work.
addPredicate(criteriaBuilder.like(root.<String>get("address.streetAddress"), streetAddress));
I solved this problem by doing:
addPredicate(criteriaBuilder.like(root.<Address>get("address").<String>get("streetAddress"), streetAddress));