From the course: Java Database Access with Hibernate

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Delete objects

Delete objects - Java Tutorial

From the course: Java Database Access with Hibernate

Start my 1-month free trial

Delete objects

- [Narrator] To continue with our CRUD operations, our Create, Read, Update, and Delete, I want to talk about deleting a row from the table. Similar to the update, the first thing we need to do is get the ID of the row we want to delete. In this case I'm going to delete John Thygeson, which is ID number 67. So let me go back over to my hibernate example code, and you can see I commented out the update on line 63, and I uncommented the command that says deleteEmployee, and it has the ID number 67. Let's scroll down for the method for deleteEmployee and take a look at the hibernate code that was added. It starts very similar to the other methods. On line 156, we start a new open session. We create a transaction object. On line 159 we begin the transaction, we use the employee ID to get the employee that we want to delete, and then on line 162 we do session.delete. And this time we pass at the object employee. Again, which is really nice if you're familiar with object oriented…

Contents