How to filter associated child class based on conditions

Viewed 31

enter image description here

public class Cluster {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

  @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.LAZY)
  @JoinTable(name = "cluster_tag", joinColumns = @JoinColumn(name = "cluster_id",
        nullable = false,
        updatable = false), inverseJoinColumns = @JoinColumn(name = "tag_id", nullable = false, updatable = false))

 private Set<Tag> tags = new HashSet<>();

}

For example if I have to select all records staring with name "Joh%" in cluster

  • whether they have matching records or not in tag all cluster records name starting with "Joh%"
    should be selected
  • if they have a matching record in tag that should be filtered based on certain conditions ie only tag should be of tag_value grater than 100.

Using Spring boot Jpa specifications.

0 Answers
Related