7

Good morning!

My Spring application doesn't seem to detect 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)

Code in the repository

public boolean existsByIdAndOwnerId(Long planetId, Integer ownerId);

  • Spring version: 4.3.12.RELEASE
  • Hibernate version: 5.2.12.Final
  • Spring Data JPA version: 1.11.7.RELEASE

Thanks in advance!

2 Answers2

1

Try naming the method: existsPlanetByIdAndOwnerId()

This link may help: https://www.baeldung.com/spring-data-derived-queries

Jack Straw
  • 490
  • 1
  • 7
  • 17
0

If you are extending CrudRepository<T, ID> in your repository it provides existById(ID) which takes id as parameter and returns Boolean based on db entry's existence. For your case you can do like this: public boolean findByIdAndOwnerId(Long planetId, Integer ownerId);

hiren
  • 1,742
  • 13
  • 20
  • 2
    This code doesn't work, returns the following error: "Null return value from advice does not match primitive return type". You'll need to make a wrapper method that will return "false" if it detects a null value from the "findById.." method (which should return an object of that type, not a boolean). – EM-Creations Nov 27 '17 at 16:16