Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using querydsl how can I check against a specific object from a set of objects that result from a One to Many relationship?

Tags:

java

jpa

querydsl

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?

like image 510
codeLes Avatar asked Jun 01 '12 21:06

codeLes


People also ask

How does querydsl work?

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.

What is Querydsl in spring?

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 .


1 Answers

Try this

QPerson qPerson = QPerson.person;
personDao.findAll(qPerson.addresses.any().zip.eq('73130'));
like image 82
Timo Westkämper Avatar answered Oct 13 '22 01:10

Timo Westkämper