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 3

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

From the course: Java Persistence with JPA and Hibernate

Solution: Art Class Management app, part 3

- [Instructor] Now I'll walk you through step by step with my solution to the challenge. I'm in the Main class. In the update method, you can see that I've created a new entity manager because this is a new use case. Then remember to open a try finally block. In the try block, begin the transaction. Then I retrieved the student entity instance that was persisted in the previous code challenge, using the find method of the entity manager. The student has an ID of one. Then I set the name of the student to Peter. Currently it's John. As I'm done doing the changes, I commit the transaction and then close the entity manager in the finally block. Make sure you call the update method in the Main method. Now let's run the program. The name of the student should now be changed from John to Peter. There's an update statement on the student table to update the name column in the console. If you go to the student table, (mouse clicking) here's the name updated to Peter. (mouse clicking) Here's…

Contents