'PostgreSQL query to filter out an empty Collection in Java

Instead of writing

.filter(tableADao -> tableADao.tableBDaos().isEmpty())

I'm looking to write a postgreSQL query to remove the empty collection. I think I need to write a join followed by IS NOT EMPTY. How can this be written?

In table A I have

@Id
@Column(name = "id_pop", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToMany(mappedBy = "tableADao", cascade = CascadeType.ALL, orphanRemoval = true)
private Collection<TableBDao> tableBDaos = new ArrayList<>();

In Table B I have

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "crr_pop_id", nullable = false)
private TableADao tableADao;


Solution 1:[1]

Try

select * from A a 
where 0 < (select count(*) from B b where a.id_pop = b.crr_pop_id )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1