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.

Finding and updating an existing entity instance

Finding and updating an existing entity instance - JPA Tutorial

From the course: Java Persistence with JPA and Hibernate

Finding and updating an existing entity instance

- [Instructor] Now, let's go to another use case. This time, you are going to find an existing entity instance and make some changes in it. Now, you'll notice that I've restructured the code a bit from what you saw in the previous video. The code to create a new entity instance has been moved to its own method named createInstance, and it has been called from the Main method. We are considering each new scenario as a new use case going forward in this course. Each new use case will have its own persistence context. This is how you'll have it in a real world application, as well. So you create an EntityManager every time you start a new use case, begin a new transaction and commit it at the end of the use case. In the book table, go to the book table, right click and show records. Now, there are three records. I simply executed this use case two more times to add two more records. That's why you see the book name as my book3 here. What you now need to do is to grab a book by the…

Contents