gpt4 book ai didi

java - Spring 框架: findBy throws Illegal Argument Exception

转载 作者:行者123 更新时间:2023-12-02 05:09:54 25 4
gpt4 key购买 nike

这是我的实体类。

@Entity
public class Profile {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long profileId;

@Transient
private String name;

@ElementCollection(fetch = FetchType.EAGER)
private Map<String, String> trNames; //Key: LanguageCode, Value: translated text
...
}

ProfileRepository类

public interface ProfileRepository extends JpaRepository<Profile, Long> {

//This method should go through the Map Collection and return a profile whose name matches the given parameter value.
Profile findByTrNames(String code, String name);

}

我创建了一个 JUnit 测试类来测试此方法。这行代码

Profile found = repository.findByTrNames("en", "Interview IT");

抛出异常。

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [en] did not match expected type [java.util.Map]; nested exception is java.lang.IllegalArgumentException: Parameter value [en] did not match expected type [java.util.Map]
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:301)
at etc..

有人可以帮我吗?

非常感谢。

最佳答案

这应该有效

@Query("select p from Profile p where p.trNames[?1] = ?2")
Profile findByTrNames(String code, String name);

更新

创建 JIRA 票证是为了支持此功能:https://jira.spring.io/browse/DATAJPA-643

关于java - Spring 框架: findBy throws Illegal Argument Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27424760/

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