Cast subqueries in QueryDSL 4

65 views
Skip to first unread message

Nelson

unread,
Dec 12, 2017, 5:37:50 AM12/12/17
to Querydsl
Hello,

I'm migration an application from QueryDSL 3 to QueryDSL 4 and I did most of the work, but I'm still struggling with two things I'm not able to migrate.

.stringValue()

In QueryDSL 3, I have that:

    SubQueryExpression<String> uuidsSubQuery = new HibernateSubQuery()
       
.from(qEntity)
       
.where(qEntity.id.eq(1))
       
.unique(qEntity.uuid.stringValue());


Column qEntity.uuid is of type UUID (PostgreSQL database), which is mapped as a java.util.UUID in class QEntity. However, I use my subquery later in a projection, and I need the subquery to return a String, not an UUID, that's why I use the .stringValue().

In queryDSL 4, I tried the following:

    JPQLQuery<String> uuidsSubQuery = JPAExpressions.selectFrom(qEntity)
       
.where(qEntity.id.eq(1))
       
.select(qEntity.uuid.stringValue());


But the method .stringValue() is not available. Is there any way to do it?

.castToNum() and .divide()

In QueryDSL 3:
    NumberExpression<Long> countEntities1 = new HibernateSubQuery().from(qEntity).where(XXXXXX).unique(qEntity.count());
   
NumberExpression<Long> countEntities2 = new HibernateSubQuery().from(qEntity).where(YYYYYY).unique(qEntity.count());
   
new HibernateUpdateClause(session, qZZZZ)
       
.set(
             ZZZZ
.count,
             countEntities1
.castToNum(BigDecimal.class).divide(countEntities2)
       
)
       
.execute();


But in QueryDSL 4, I did not find a way to apply the castToNum(BigDecimal.class) and the .divide() operation between my two subqueries. Is there any equivalent?

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages