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