How to write this query in queryDsl
SELECT a.id, 
(SELECT count(*) FROM ancestors_table t where t.ancestors LIKE CONCAT('%,',a.id,',%') )
  FROM ancestors_table a; 
I struggle with the LIKE CONCAT('%,',a.id,',%') part.
THE SOLUTION
where(t.ancestors.like(
                Expressions.stringTemplate("'%,'")
               .concat(Expressions.stringTemplate("{0}" , a.id ))
               .concat(Expressions.stringTemplate("',%'")) 
))
                Not entirely sure, but something like this:
where(t.ancestors.like(Expressions.asString("%").concat(a.id).concat("%")))
If a.id is a number then you need to convert it into a string: 
where(t.ancestors.like(Expressions.asString("%").concat(a.id.stringValue()).concat("%")))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With