Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Criteria - Return parent records that have child records

All,

I'm probably over-analyzing this problem, but...

Given table "A" with two one-to-many relationships "A1" and "A2", return all records in table "A" that have at least one child record in either table "A1" or "A2"...

I'm not necessarily interested in knowing what the child data is, but rather that I just have child data.

Thanks!

like image 358
Tim Reddy Avatar asked Dec 05 '25 00:12

Tim Reddy


1 Answers

You need a Restrictions.isNotEmpty() criterion:

List<A> r = s.createCriteria(A.class)
    .add(Restrictions.or(
        Restrictions.isNotEmpty("a1"), 
        Restrictions.isNotEmpty("a2"))).list();
like image 144
axtavt Avatar answered Dec 07 '25 15:12

axtavt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!