Java "update myTable where myColumn in ('interesting', 'values')" 的 QueryDsl?
Java QueryDsl for "update myTable where myColumn in ('interesting', 'values')"?
我正在尝试在 QueryDsl 中翻译此查询:
update myThings set firstColumn = 'newValue' where secondColumn in ('interesting', 'stuff')
我花了几个小时寻找文档,但 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();
我能找到的只有 API 定义,但后来我迷失在泛型中,其他任何我仍然难以理解的 "new" java 概念。一个例子将不胜感激。
你必须使用 new JPAUpdateClause(session, myThings)
:
JPAUpdateClause<myThings> update = new JPAUpdateClause(session, myThings);
update.set(myThings.firstColumn, "newValue")
.where(myThings.secondColumn.in(interestingValues))
.execute();
如果您使用的是休眠模式,请改用HibernateUpdateClause()
;
我正在尝试在 QueryDsl 中翻译此查询:
update myThings set firstColumn = 'newValue' where secondColumn in ('interesting', 'stuff')
我花了几个小时寻找文档,但 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();
我能找到的只有 API 定义,但后来我迷失在泛型中,其他任何我仍然难以理解的 "new" java 概念。一个例子将不胜感激。
你必须使用 new JPAUpdateClause(session, myThings)
:
JPAUpdateClause<myThings> update = new JPAUpdateClause(session, myThings);
update.set(myThings.firstColumn, "newValue")
.where(myThings.secondColumn.in(interestingValues))
.execute();
如果您使用的是休眠模式,请改用HibernateUpdateClause()
;