简体   繁体   English

JPA 本机查询问题说没有找到类型的属性

[英]Issue with JPA native queries saying No property found for type

I have a spring boot application using JPA native queries.我有一个使用 JPA 本机查询的 spring 启动应用程序。 These queries are located in a separate properties file.这些查询位于单独的属性文件中。 I have 3 queries called getSomething and getSomethingWithSomeParam and getSomethingWithOtherParam.我有 3 个查询,分别称为 getSomething、getSomethingWithSomeParam 和 getSomethingWithOtherParam。 When it was just getSomething, the endpoint worked fine.当它只是 getSomething 时,端点工作正常。 When I added getSomethingWithSomeParam endpoint/query, it also worked as expected.当我添加 getSomethingWithSomeParam 端点/查询时,它也按预期工作。

However when I added getSomethingWithOtherParam, JPA started throwing this error:但是,当我添加 getSomethingWithOtherParam 时,JPA 开始抛出此错误:

IllegalArgumentException: Failed to create query for method ... DataAccessLayer.getSomethingWithOtherParam(...)! No Property getSomething found for type DTO!

This is what the data access layer looks like:这是数据访问层的样子:

@Query(nativeQuery = true)
public List<String> getSomething();

@Query(nativeQuery = true)
public List<String> getSomethingWithSomeParam(@Param("some") String some);

@Query(nativeQuery = true)
public List<String> getSomethingWithOtherParam(@Param("other") String other);

Does JPA not allow multiple queries with similar names if they have the same number and type of parameters?如果参数数量和类型相同,JPA 是否不允许具有相似名称的多个查询? Why is JPA getting confused in which query to map each query method to?为什么 JPA 在哪个查询到 map 的每个查询方法中变得混乱?

I think your code is not a problem because I have used this method many times.我认为你的代码没有问题,因为我已经多次使用这种方法。 Because methods are called statically from another layer, there is no problem defining methods and parameters in your code.因为方法是从另一层静态调用的,所以在代码中定义方法和参数没有问题。 You may have set up server-side settings that cause errors.您可能设置了导致错误的服务器端设置。 To do this, you can create a simple project to test this.为此,您可以创建一个简单的项目来测试它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM