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.

Update objects

Update objects - Java Tutorial

From the course: Java Database Access with Hibernate

Start my 1-month free trial

Update objects

- [Instructor] A big benefit of Hibernate is that it automatically manages any updates made to persistent objects. When a change is made, the Hibernate session cues the change for persistence to the database using SQL. Another way is we can actually force Hibernate to make the change by issuing a commit command. Let's take a look at the later. So here is my Hibernate example program again, the same program that I used to add objects to the database. I'm going to scroll down just a little bit and you'll see on line 63, I'm calling a method that I wrote called updateEmployee. I'm passing it the employee id and the new salary that I want that employee to make. So let's scroll down. The update method is located here on line 137, and again, it takes in the employee id and the salary. Remember, we want to create our session only when we need it. So at this point, I'm going to do an open session on line 138. I'm going to create another transaction object. I'm going to try on line 140 to…

Contents