I created a view to reduce the query complexity. The inheritance boundary seemed to be a huge problem.
Dealing with polymorphic classes in Criteria API
-
29-06-2022 - |
Question
For a search feature i have to implement a quite join heavy query to return all location based services from specified ranges (PLZAreaRange). As you can see there are a lot of inheritance structures till i reach the PLZAreaRange to compare the search criteria with the plzText.
public abstract class LocationbasedService {
@OneToOne
private Geography geography;
}
public abstract class Geography {
@OneToOne(mappedBy="geography")
private LocationbasedService locationbasedService;
}
public class Areageography extends Geography {
@ManyToOne
private Area from;
@ManyToOne
private Area to;
}
public abstract class Area {
}
public class PLZArea extends Area {
@OneToMany(mappedBy = "plzArea")
private List<PLZAreaRange> abschnitte = new ArrayList<PLZAreaRange>();
}
public class PLZAreaRange {
@ManyToOne(cascade=CascadeType.ALL)
private PLZArea plzArea;
private String plzText;
}
How do i join down to this entity to select all Services which have the plzText in ("test1", "test2")?
greetings m
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow