From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Solution: Art Class Management app, part 5

Solution: Art Class Management app, part 5 - JPA Tutorial

From the course: Java Persistence with JPA and Hibernate

Solution: Art Class Management app, part 5

(upbeat music) - Here's how you can write the queries to retrieve the data that Orange Valley Community Arts Association needs. The first JPQL query is for listing all the students. I've written the query as "SELECT s FROM Student s". S is the reference variable for the student entity. Then call the create query method of the entity manager and pass the query. The query returns student entity instances, so the type should be student. After that, retrieve the result list and print using a four H loop. The second query is to list the students who are attending classes on Monday. Since the day of the week is in the art class entity, I query from the art class entity. So the query goes like this. SELECT c.students FROM ArtClass c WHERE c.dayOfWeek equals to Monday. C is the reference variable for the art class entity. The art class entity has a list of students. I'm retrieving it with c.students. Then the where clause contains the filter criteria. The day of the week has to be Monday. The…

Contents