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

标签 java spring-boot jpa

我正在使用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/

相关文章:

java - 如何使这段 Java 代码正常运行? [多线程,竞争条件]

java - java中 '>>'和 '/'、移位和除法有什么区别

spring-boot - 如何修复Spring Boot Gradle:带有二进制文件的processResources

java - 获取Connection用于连接数据库的url

java - 我认为接口(interface)不能在java中实例化

java - 日志记录异常问题

Java - 读取 CSV 并将对象 [] 值转换为字符串值

java - MyBatis - 使用自定义对象调用存储过程

java - 服务器发送事件 Spring Webflux 返回事件名称以响应其余 Controller

java - 当数据没有被持久化时convertToDatabaseColumn?