【问题标题】:Spring Data 1.11.7 No property existsBySpring Data 1.11.7 No property existsBy
【发布时间】:2018-04-28 15:14:31
【问题描述】:

早上好!

我的 Spring 应用程序似乎没有检测到 existsBy projections

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property existsById found for type Planet!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)

存储库中的代码

public boolean existsByIdAndOwnerId(Long planetId, Integer ownerId);

  • 春季版:4.3.12.RELEASE
  • 休眠版本:5.2.12.Final
  • Spring Data JPA 版本:1.11.7.RELEASE

提前致谢!

【问题讨论】:

标签: java spring spring-data-jpa


【解决方案1】:

尝试命名方法:existsPlanetByIdAndOwnerId()

此链接可能会有所帮助: https://www.baeldung.com/spring-data-derived-queries

【讨论】:

    【解决方案2】:

    如果您在存储库中扩展CrudRepository&lt;T, ID&gt;,它会提供existById(ID),它将id 作为参数并根据数据库条目的存在返回布尔值。对于您的情况,您可以这样做:public boolean findByIdAndOwnerId(Long planetId, Integer ownerId);

    【讨论】:

    • 此代码不起作用,返回以下错误:“来自通知的空返回值与原始返回类型不匹配”。您需要创建一个包装器方法,如果它从“findById..”方法检测到空值(应该返回该类型的对象,而不是布尔值),它将返回“false”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 2015-06-26
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多