简体   繁体   English

Spring 存储库更新 - 找不到类型的属性

[英]Spring Repository Update - No property found for type

I have searched on StackOverflow a solution for this on the other discussions about this same error, but couldn't find an answer for this specific scenario.我在 StackOverflow 上搜索了有关此相同错误的其他讨论的解决方案,但找不到针对此特定情况的答案。

Here is what's happening.这是正在发生的事情。

I have the following Spring Repository.我有以下 Spring 存储库。

@Repository
@Transactional
public interface UserRepository extends CrudRepository<User, Long>{   

       @Modifying
       @Query("update User u set u.userDesc = :userDesc where u.userName = :userName")
       public int updateUser(String userDesc, String userName);
}

Getting this error.收到此错误。

Could not create query for public abstract int com.xyz.UserRepository.updateUser(java.lang.String,java.lang.String);无法为 public abstract int com.xyz.UserRepository.updateUser(java.lang.String,java.lang.String) 创建查询; Reason: Failed to create query for method public abstract int com.xyz.UserRepository.updateUser(java.lang.String,java.lang.String);原因:无法为方法 public abstract int com.xyz.UserRepository.updateUser(java.lang.String,java.lang.String) 创建查询; No property 'updateUser' found for type 'User';找不到类型“User”的属性“updateUser”;

Why?为什么?

Probably not related, since the exception is from JPA and not JDBC, but you are using a class named User as your data class name and table name as I can see from the query.可能不相关,因为异常来自 JPA 而不是 JDBC,但是您正在使用名为User的 class 作为您的数据 class 名称和表名,正如我从查询中看到的那样。 Depending on what underlying database you are using, you could be running into conflicts relating to restricted keywords of that database.根据您使用的底层数据库,您可能会遇到与该数据库的受限关键字相关的冲突。

For example, in newer versions of H2 the USER keyword is restricted.例如,在较新版本的 H2 中, USER关键字受到限制。 https://www.h2database.com/html/advanced.html https://www.h2database.com/html/advanced.html

On another note, if you run a clean SpringBoot project with the following:另一方面,如果您使用以下内容运行一个干净的 SpringBoot 项目:

import jakarta.persistence.*;

@Entity
public class UserTest {
    
    public UserTest(){}

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id", nullable = false)
    public Long id;

    public String userDesc;

    public String userName;

}

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
@Transactional
public interface UserRepository extends CrudRepository< UserTest, Long> {

    @Modifying
    @Query("update UserTest u set u.userDesc = :userDesc where u.userName = :userName")
    public int updateUser(String userDesc, String userName);
}

It does run and the update method works just fine, so the issue must be somewhere else in your code, or in your imports which you are not showing.它确实运行并且更新方法工作得很好,所以问题一定是在你的代码中的其他地方,或者在你没有显示的导入中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data Neo4j存储库组合错误:找不到类型为YYYY的属性XXXX - Spring Data Neo4j Repository Composition error: No property XXXX found for type YYYY 尝试使用Spring Data JPA创建自定义存储库时,找不到类型错误的属性 - No property found for type error when try to create custom repository with Spring Data JPA 将 EntityGraphJpaSpecificationExecutor 添加到存储库后找不到类型的属性 - No property found for type after adding EntityGraphJpaSpecificationExecutor to repository Spring 数据 JPA - “找不到类型的属性”异常 - Spring Data JPA - "No Property Found for Type" Exception Spring 数据 JDBC:找不到类型的此类属性 - Spring Data JDBC: No such property found for type 在 Spring 自定义查询中找不到类型的属性 - No property found for type in Spring custom query Spring 启动 - 未找到用户类型的属性 ID - Spring boot - No property ID found for type User Spring boot sort.by() 找不到类型的属性 - Spring boot sort.by() No property found for type Spring JPA:PropertyReferenceException:找不到类型的属性findAll - Spring JPA: PropertyReferenceException: No property findAll found for type Spring共享自定义存储库,说明未找到sharedCustomMethod的属性 - Spring Shared Custom Repository stating that no property found for sharedCustomMethod
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM