1

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();
java dev
  • 313
  • 1
  • 3
  • 12
  • Projections support was intended yes. Can you please share the stacktrace for the exception? – Jan-Willem Gmelig Meyling Sep 20 '21 at 14:01
  • Thanx @Jan-Willem Gmelig Meyling But the result is [ 1, "2021-08-25T20:29:41.478+00:00", "2021-08-25T20:29:41.478+00:00", "test@domain.ya", 10.0, 20.0, 0.0 ] Why not field: value? – java dev Sep 20 '21 at 14:05
  • Ignore NPE. I resolved it from this https://stackoverflow.com/questions/67295962/blaze-persistence-skip-null-parameters-in-where-expression?rq=1 But give me advice on how to make query return data as {Field: Value} not value only? – java dev Sep 20 '21 at 14:17

1 Answers1

3

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
    )