0

I am trying to write a findBy in the spring data where I want All employees where employees first department status is ACTIVE. Is it possible using spring data method name, without using custom query?

something like List findByDepartmentFirstStatusIsActive();

I tried few, but none are working so I guess No!!!

4
  • Try something like : findByDepartmentFirstStatus(FirstStatus status); or findByDepartment_FirstStatus(FirstStatus status); Commented Aug 15, 2016 at 10:55
  • I tried it but complains org.springframework.data.mapping.PropertyReferenceException: No property firstStatus found for type Department Commented Aug 15, 2016 at 11:05
  • and _ is just to resolve conflict, so same error Commented Aug 15, 2016 at 11:06
  • That's because there is no property named firstStatus in Department. Can you show us your class Department ? Commented Aug 15, 2016 at 12:05

1 Answer 1

2

You can use under score character _ in order to separate nested property. For example:

findByDepartment_FirstStatus(Status status);

I assume that you have a property with name firstStatus of type Status in Department class, and obviously a field with name department of type Department in your Employee class (for example!).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.