如何在Spring框架中修复UnsatisfiedDependencyException,当使用@Query时

问题描述 投票:0回答:1

我已经使用springboot创建了WEB服务,使用JpaRepository这样的简单方法,例如.findAll(),一切正常。当我尝试使用@Request-SQL请求的JPQL时,出现了问题。

我尝试了一个简单的请求@Query(“从qcm.tabledeteste t中选择内容,其中t.id =?1”]

这是一个简单的示例,但我的真正目标是更新数据

在DAO中...

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface TesterDao extends  JpaRepository<Tester, String> { 
    @Query("SELECT content FROM autosv.tester t where t.id = ?1")
    String  testerQuery(String id); 
}

在控制器名称中:TesterController....

TesterDao tDao;
@GetMapping(value = "/testerQuery")
    public String  testerQuery() {
        String t = tDao.testerQuery("7");       
        return t;
}

...

 org.springframework.beans.factory.UnsatisfiedDependencyException: Error
 creating bean with name 'TesterController': Unsatisfied dependency expressed
 through field 'tDao'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean
 with name 'TesterDao': Invocation of init method failed; nested exception is
 java.lang.IllegalArgumentException: Validation failed for query for method 

public abstract java.lang.String 

com.example.qcm.qcm.dao.TabledetesteDao.getTabledetestQuery(java.lang.String)


!

......

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: is not mapped
sql hibernate spring-boot jpa jpql
1个回答
0
投票

在查询中使用类名Tester而不是autosv.tester。

© www.soinside.com 2019 - 2024. All rights reserved.