【问题标题】:QuerySyntaxException: Table is not mapped [Update Table BOMmodel Set PA13 = Materialvalue + ReqQTY ]QuerySyntaxException:表未映射 [更新表 BOMmodel 设置 PA13 = Materialvalue + ReqQTY ]
【发布时间】:2020-03-01 20:26:56
【问题描述】:

我正在尝试使用其他两列(Materialvalue,ReqQTY)的总和来更新一列,正如您在上面看到的那样

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;
import com.example.demo2.model.BOMmodel;

public interface BOMrepository extends JpaRepository<BOMmodel, String> {
    @Modifying
    @Query("Update Table BOMmodel Set PA13 = Materialvalue + ReqQTY ")
      int updatePA();
}

实体看起来像这样

@Table(name = "bom_table")
@Entity
public class BOMmodel {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long id;
    public String ComponentNo;
    public Float ReqQTY;
    public String MatGroup;
    public Float Materialvalue;
    public Float PA13;
    public String kw;

但我收到以下错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'controller': Unsatisfied dependency expressed through field 'BOMrepos'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BOMrepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract void com.example.demo2.repository.BOMrepository.updatePA()!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'BOMrepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract void com.example.demo2.repository.BOMrepository.updatePA()!

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Table is not mapped [Update Table BOMmodel Set PA13 = Materialvalue + ReqQTY ]

我做了一些研究,发现使用表名而不是实体是导致此错误的常见原因,但事实并非如此。 那么请有其他想法吗?

【问题讨论】:

    标签: java mysql spring-data-jpa


    【解决方案1】:
    Update bom_table Set PA13 = Materialvalue + ReqQTY
    

    使用它

    【讨论】:

    • 非常感谢@Mayank,你启发了我解决这个问题。我所做的是删除行 @Table(name = "bom_table") 并将存储库代码更改为 @Transactional @Modifying @Query("Update BOMmodel Set PA13 = Materialvalue + ReqQTY ") int updatePA(); 现在它就像一个魅力
    • 欢迎你。当你处理你的问题时,你会学到很多东西。所以继续前进。
    【解决方案2】:

    我找到的解决方案是删除行@Table(name = "bom_table")并将存储库代码更改为此@Transactional @Modifying @Query("Update BOMmodel Set PA13 = Materialvalue + ReqQTY ") int updatePA(); 现在它就像一个魅力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 2018-09-07
      • 2014-03-04
      相关资源
      最近更新 更多