PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 29, 2022

[FIXED] How to translate from native sql to querydsl expression right?

 October 29, 2022     java, left-join, querydsl, spring, sql     No comments   

Issue

Given the following native SQL query:

@Query(
value =
"SELECT "
+ "jp.BLABSTATUSID BlabStatus, "
+ "s.BLABSTATUSBEZ BlabStatusBez, "
+ "COUNT(*) sumvalue "
+ "FROM JP jp "
+ " LEFT JOIN BLAB_STATUS s "
+ " ON jp.BLABSTATUSID = s.BLABSTATUSID "
+ "GROUP BY jp.BLABSTATUSID, s.BLABSTATUSBEZ",
nativeQuery = true)

that I use in my Java / spring context, I have to switch to querydsl.

I tried:

final QJpEntity e = jpEntity;
final QBlabStatusEntity f = blabStatusEntity;

    return jpaQueryFactory
        .from(e)
        .leftJoin(e.blabStatus, blabStatusEntity)
        .on(blabStatusEntity.blabstatusid)
        .groupBy(e.blabStatus.blabstatusid, f.blabstatusbez)
        .select(
            Projections.constructor(
                JPStatisticCounter.class,
                e.blabStatus,
                f.blabstatusbez,
                e.count()))
        .fetch();

but it cannot compile because it seems syntactically wrong.

Any ideas?


Solution

solved, it was a constructor type mismatch



Answered By - DerBenniAusA
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing