left join with spring data jpa and querydsl

2,145 views
Skip to first unread message

Frey Zheng

unread,
Apr 15, 2014, 3:24:30 AM4/15/14
to quer...@googlegroups.com
Hi,

I am using spring data jpa and querydsl and trapped on how to write simple nice query to left join two tables.
Suppose I have an Project entity and a Task entity with OneToMany relationship defined in Project, I would like to do something like:

select * from project p left join task t on p.id = t.project_id where p.id = searchTerm

I have a ProjectRepository interface, which extends JpaRepository and QueryDslPredicateExecutor.
That gives me access to method:

Page<T> findAll(com.mysema.query.types.Predicate predicate, Pageable pageable) 

I know that left join can be easily achieved by creating a new JPAQuery(entityManager). But I do not have entity manager explicitly injected with spring data jpa.
Is there nice and simple way to build a predicate with left join?
Wish someone in this group have experienced this requirement and is able to give me an example.
Thank you.

Frey.

timowest

unread,
Apr 15, 2014, 4:16:11 PM4/15/14
to quer...@googlegroups.com
Hi.

left joins can't be really created via predicates.

The closest thing is QProject.project.tasks.any().id.eq(searchTerm), but the effect is different, it's translated into a subquery.

Timo

Rishu Oberoi

unread,
Feb 28, 2017, 12:23:14 PM2/28/17
to Querydsl
Anyone found a solution to this yet? Facing the same issue!
Reply all
Reply to author
Forward
0 new messages