I'm trying to translate this query in QueryDsl:
update myThings set firstColumn = 'newValue' where secondColumn in ('interesting', 'stuff')
I spent hours looking for documentation but the java fu is just not strong enough in this one... :( I can find all kinds of QueryDsl example, but I cant find any for this. I will probably need SimpleExpression.eqAny(CollectionExpression), but I can't figure out how to build such a CollectionExpression around my simple list of strings.
List<String> interestingValues = Arrays.asList("interesting", "stuff");
queryFactory.update(myThings)
    .set(myThings.firstColumn, "newValue")
//  .where(myThings.secondColumn.in(interestingValues)
//         'in' will probably try to look in table "interestingValues"?
//  .where(myThings.secondColumn.eqAny(interestingValues)
//         'eqAny' seems interesting, but doesn't accept a list
    .execute();
All I can find is API definitions, but then I get lost in generics any other "new" java concepts which I still have trouble understanding. An example would be very much appreciated.
You have to use new JPAUpdateClause(session, myThings):
JPAUpdateClause<myThings> update = new JPAUpdateClause(session, myThings);
update.set(myThings.firstColumn, "newValue")
      .where(myThings.secondColumn.in(interestingValues))
      .execute();
If you are using hibernate, use HibernateUpdateClause() instead;
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