Java QueryDsl是否为“更新myTable其中myColumn在('有趣','值')中”?

Sad*_*nny 3 java querydsl

我正在尝试在QueryDsl中翻译此查询:

update myThings set firstColumn = 'newValue' where secondColumn in ('interesting', 'stuff')
Run Code Online (Sandbox Code Playgroud)

我花了数小时寻找文档,但是Java fu在这个文档中不够强大... :(我可以找到各种各样的QueryDsl示例,但是我找不到任何示例。我可能需要SimpleExpression.eqAny(CollectionExpression) ,但我不知道如何在简单的字符串列表中构建这样的CollectionExpression。

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();
Run Code Online (Sandbox Code Playgroud)

我所能找到的只是API定义,但后来我迷上了泛型的任何其他“新” java概念,但我仍然很难理解。一个例子将不胜感激。

Gui*_* F. 5

您必须使用new JPAUpdateClause(session, myThings)

JPAUpdateClause<myThings> update = new JPAUpdateClause(session, myThings);
update.set(myThings.firstColumn, "newValue")
      .where(myThings.secondColumn.in(interestingValues))
      .execute();
Run Code Online (Sandbox Code Playgroud)

如果您正在使用休眠模式,请HibernateUpdateClause()改用;