Is Blaze-Persistence Querydsl integration support projections?

1k Views Asked by At

How to use Projections with Blaze-Persistence Querydsl?

And in bellow example when criteria.getEmail() give me NullPointerException. So How I can overcome NullPointerException for more wheres?

cbf.create(em, WalletReportDto.class)
                .fromSubquery(WalletCTE.class, "offerCTO").from(TenantBalanceOffers.class, "tbo")
                .bind("walletId").select("tbo.wallet.id")
                .bind("amount").select("SUM(tbo.amount)")
                .groupBy("tbo.wallet.id").end()

                .joinOn(TenantWallet.class, "tw", JoinType.INNER)
                .onExpression("offerCTO.walletId = tw.id")
                .end() //

                .select("MIN(tw.createdDate)", "fromtDate").select("MAX(tw.createdDate)", "toDate")

                .select("tw.customer.email", "email")
                .select("sum(offerCTO.amount)").where("tw.customer.email").eq(criteria.getEmail())

                .groupBy("tw.id")

                .getResultList();
1

There are 1 best solutions below

2
Jan-Willem Gmelig Meyling On BEST ANSWER

You need to use the Blaze-Persistence Querydsl integration to use Querydsl projections with Blaze-Persistence's query features.

List<WalletReportDto> result = new BlazeJPAQuery<>(em, cbf)
    .from(new BlazeJPAQuery<>()
          .from(QTenantBlanceOffers.tenantBlanceOffers)
          .bind(QWalletCTE.walletCTE.walletId, QTenantBlanceOffers.tenantBlanceOffers.wallet.id)
          .bind(QWalletCTE.walletCTE.amount, QTenantBlanceOffers.tenantBlanceOffers.amount.sum())
    , QWalletCTE.walletCTE)
    .innerJoin(QTenantWallet.tenantWallet)
    .on(QTenantWallet.tenantWallet.id.eq(QWalletCTE.walletCTE.walletId))
    .transform(Projections.bean(
        WalletReportDto.class,
        QTenantWallet.tenantWallet.createdDate.min(),
        QTenantWallet.tenantWallet.createdDate.max(),
        QTenantWallet.tenantWallet.customer.email,
        QWalletCTE.walletCTE.id
    )