From the course: Spring Data

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Query by Example

Solution: Query by Example - Spring Tutorial

From the course: Spring Data

Solution: Query by Example

(upbeat music) - [Instructor] Okay, let's see if you figured it out. So on line 40, we are looking up the Humanities Department with the findOne method on the departmentRepo and passing in the probe for Example.of, and we're simply just instantiating an object of type Department, setting the name attribute to the Humanities string, and leaving the chair null. And then, for Staff to look up professorBlack, there would be a findAll because there could be many professors with the last name Black, whereas we expect only one Humanities Department. So, the findAll in passing in Example.of, and then it's a Staff member. So we instantiate Staff. And then, we instantiate a Person, and put the firstName of the Person attributes in null, and the lastName of Black and the string. And then, we stream the output of that. And then, we just get the findFirst because we're only interested, we know for a fact that there's only one professor Black, but there, you know, we think there could be, but we're…

Contents