gpt4 book ai didi

java - 我怎样才能修改mysql更新方法?

转载 作者:行者123 更新时间:2023-12-02 01:17:53 25 4
gpt4 key购买 nike

我想从 dto 列表更新 mysql 表,但有一些异常,比如语法问题,这是我的代码:

@Override
@Transactional
public void updateCustomCategory(List<ItemDto> itemDtoList) {
if (CollectionUtils.isNotEmpty(itemDtoList)) {
for (ItemDto itemDto : itemDtoList) {
Long l1CustomCategoryId = itemDto.getL1CustomCatId();
Long l2CustomCategoyId = itemDto.getL2CustomCatId();
StringBuilder query =
new StringBuilder(
"update ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId");
Query q = this.em.createQuery(query.toString());
q.setParameter("l1CustomCategoryId", l1CustomCategoryId);
q.setParameter("l2CustomCategoyId", l2CustomCategoyId);
q.setParameter("itemId", itemDto.getItemId());
q.executeUpdate();
}
}
}

异常如下:

2019-10-04 14:49:00.227 ERROR 11909 --- [nio-9092-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: and near line 1, column 108 [update com.shopee.data.dto.brandseller.item.ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: and near line 1, column 108 [update com.shopee.data.dto.brandseller.item.ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId]] with root cause

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: and near line 1, column 108 [update com.shopee.data.dto.brandseller.item.ItemDto item set item.l1CustomCategoryId = :l1CustomCategoryId and item.l2CustomCategoryId = :l2CustomCategoyId where itemId = :itemId]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:296) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:188) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile

最佳答案

您不能将 ANDSET 一起使用,而是用逗号分隔它们。正确的语法是

设置 item.l1CustomCategoryId = :l1CustomCategoryId, item.l2CustomCategoryId = :l2CustomCategoyId

关于java - 我怎样才能修改mysql更新方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58231479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com