这是我的实体类。
@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 Test Class来测试这个方法。 这行代码
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..
有人可以帮助我吗?
非常感谢。
答案 0 :(得分:2)
这应该有效
@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