QueryDSL / JPQL : how to build a join query?

后端 未结 1 2042
梦毁少年i
梦毁少年i 2021-02-13 12:10

I\'ve tried to read through the QueryDSL docs but I am still very confused. I\'m accustomed to writing a lot of SQL, but this is my first real crack at using QueryDSL w/ JPQL (

相关标签:
1条回答
  • 2021-02-13 13:03

    This should work

    public Contact getContact(long providerId, long contactId) {
        QProvider provider = QProvider.provider;
        QContact contact = QContact.contact;
        return new JPAQuery(em).from(provider)
            .innerJoin(provider.contact, contact)
            .where(provider.id.eq(providerId), contact.id.eq(contactId))
            .singleResult(contact);
    }
    
    0 讨论(0)
提交回复
热议问题