I have an @Entity Location which has a field :
Set<Alert> openAlerts
Then I have an @Entity Alert which has two fields :
AlertState statewhich is an enum (can beOPENorCLOSED)Location originatedInwhich is the location where the alert originated.
At the moment in Location I have :
@OneToMany(mappedBy = "originatedIn")
@JsonIgnoreProperties({"originatedIn"})
private Set<Alert> openAlerts;
It retrieves all the alerts linked to the location (open or closed).
I want to replace that field with Integer numberOpenAlerts.
This new field should retrieve and count only the alerts linked to the location that have the AlertState of OPEN.
How can I do that ?