I have a Person JPA entity, and my Person has multiple addresses (OneToMany relationship from Person to Address). I want to be able to do a query for all people that have a particle zipcode but I'm not sure after looking at the querydsl documentation how to properly handle the collection.
I can access the addresses but I'm not sure what to do with them:
QPerson qPerson = QPerson.person;
personDao.findAll(qPerson.addresses._SPECIFICADDRESS_.zip.eq('73130'));
How can I get the SPECIFICADDRESS I'm looking for?
Querydsl tries provide a fluent API by which clients can build a query based on Bean properties. The API is derived from the persistence store or Object model, but it is store- and model-agnostic at the same time, so it allows the client to create and use the query with ease.
Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API. Spring Data modules offer integration with Querydsl through QuerydslPredicateExecutor .
Try this
QPerson qPerson = QPerson.person;
personDao.findAll(qPerson.addresses.any().zip.eq('73130'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With