gpt4 book ai didi

java - org.springframework.core.convert.ConverterNotFoundException : No converter found capable of converting from type Account to type AllAccount

转载 作者:行者123 更新时间:2023-12-02 01:29:00 32 4
gpt4 key购买 nike

我正在使用SpringBoot和JPA来调用db,我遇到异常

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [com.xxx.central.model.Account] to type [com.xxx.central.model.AllAccount]

下面是我的代码

Account.java

@Entity
@Table(name = "account")
public class Account implements Serializable {

AllAccount.java

@Entity(name="allAccounts")
@Table(name = "account")
public class AllAccount implements Serializable {

AccountRepository.java

@RepositoryDefinition(domainClass = Account.class, idClass = Integer.class)
public interface AccountRepository extends CrudRepository<Account, Integer>
{

public List<AllAccount>
findByIsActiveAndClientNameIgnoreCaseContainingOrderByAccountCreatedDesc(
Boolean active, String clientNameSearchString);
}

当我从我的服务类调用上面的存储库时,我收到异常。我哪里出错了?谢谢。

最佳答案

public interface AccountRepository extends CrudRepository<Account, Integer> 

此行使您的 Repository 类仅返回对象 Account 类型。

这就是为什么当你打电话时

public List<AllAccount> 
findByIsActiveAndClientNameIgnoreCaseContainingOrderByAccountCreatedDesc

它尝试从类型 Account 转换为 AllAccount 但它不能,因此出现异常。

您可以为 AllAccount 创建一个不同的存储库类,或者通过更改为

来更改此存储库类以返回 AllAccount
public interface AccountRepository extends CrudRepository<AllAccount, Integer> 

关于java - org.springframework.core.convert.ConverterNotFoundException : No converter found capable of converting from type Account to type AllAccount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56428509/

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