1

I am using this JPAQueryFactory .select to get the data

queryFactory.select(
 Projections.bean(detailDTO.class,
 qEmpcate.id,
 qEmcate.date.as("completeDate"),
 qEmpcate.status, 
 qCete_name
 ))
 .from(qEmpcate)
 .leftJoin(qCete).on(qCete.id.eq(qEmpcate.cete_id))
 .fetch();

complete date is sometimes NULL and it causes error in other components. In SQL I would fix it simply by using something like NVL(qEmcate.date,'') but I am quite new to JPAQueryFactory (Spring boot in general) and I realized it wouldnt be that easy. JPAQueryFactory doesnt recognize NVL and COALESCE is not working for me. Is there any other function in JPAQueryFactory that replaces NULL values with some String ?

Thank you for help.

asked Oct 25, 2021 at 16:27
3
  • In Querydsl you should use coalesce for this. What issue do you have with coalesce? Commented Oct 26, 2021 at 9:40
  • Because I want the NULL value of complete date to be empty string. Coalesce needs representation of both column and value to be same type - so in my case I will receive SQL error 22007 that representation of datetime and string was incorrect. To fix this I would need to use trim - COALESCE(trim(date), '') and I dont think I can use trim with coalesce that way in queryDLS Commented Oct 26, 2021 at 12:14
  • You can cast the date to a string in Querydsl. Commented Oct 26, 2021 at 18:00

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.