I have recently started to refactor my project because I had to add an extra column to some of my table. The extra column is an Enum (Pending, or Active). Because of that change I would need now to refactor ALL my queries to only retrieves a row if the status is ACTIVE.
After some research I found that we can annotate an Entity with the @Where annotation. it works fine where I use it on a simple column but my table look like this:
@Where(clause = 'state='ACTIVE'")
@Entity
public class Place {
@Column(name="id_place")
private String placeId;
@Column(name="name")
private String palceName;
@OneToMany(mappedBy = "place")
private Set<PlaceTag> placeTag;
...
...
}
@Where(clause = 'state='ACTIVE'")
@Entity
public class Tag {
@Column(name="id_tag")
private String tagId;
@Column(name="name")
private String tagName;
@OneToMany(mappedBy = "tag")
private Set<PlaceTag> placeTag;
...
...
}
@Where(clause = 'poi.state='ACTIVE' AND tag.state='ACTIVE")
@Entity
public class PlaceTag {
@Column(name="id")
private String id;
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "place_id")
private Place place;
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "tag_id")
private Tag tag;
...
...
}
Now my question would be how can make this statement ONLY return the places and tags that are ACTIVE ?
SELECT pt FROM PlaceTag pt;
Is this possible? Or will I have to write the query Explicitly ?
Thank you