From the course: Java Persistence with JPA and Hibernate
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Removing an entity instance - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
Removing an entity instance
- [Instructor] In JDBC, among the other CRUD operations, you would also need to perform the DELETE operation. Using ORM, or in other words, Hibernate, is this possible? Well, it's possible, but the concept of removal in ORM is a little bit different to JDBC. In the entity manager, there's a method named Remove. In the code for this use case, you can see that there's a find for a book with an ID of one. If it's not already in the context, it will be brought from the database. If not, the existing instance in the context will be used. So let's call the Remove method to remove book1. So below book1 here, we call em.remove and parse in book1. What really happens here is that the instance book1 will be marked for removal, but it will remain within the context. At the end of the transaction, Hibernate will look at the context and see what changes have happened. It will see that entity instance book1 has been marked for removal and therefore, it shows a delete query on the book database…
Contents
-
-
-
-
-
-
-
(Locked)
Finding and updating an existing entity instance7m 12s
-
(Locked)
Attaching and detaching an entity instance4m 42s
-
(Locked)
Removing an entity instance2m 42s
-
Using the getReference() and refresh() methods5m 53s
-
(Locked)
Using composite keys on an entity8m 1s
-
(Locked)
Challenge: Art Class Management app, part 31m 29s
-
(Locked)
Solution: Art Class Management app, part 34m 8s
-
(Locked)
-
-
-
-