1 00:00:01,330 --> 00:00:04,810 Now that you've got some experience storing POJO data into a database, 2 00:00:04,810 --> 00:00:07,500 let's consider the work we have left using this approach. 3 00:00:08,500 --> 00:00:12,580 We would still need to incorporate updating and deleting existing contacts. 4 00:00:12,580 --> 00:00:16,610 Also, we haven't created a similar approach for fetching all contacts and 5 00:00:16,610 --> 00:00:19,030 storing them into a list of contact objects. 6 00:00:20,420 --> 00:00:23,510 And we'd probably want to have groups in our contact manager. 7 00:00:23,510 --> 00:00:25,930 So we should probably create a POJO for a group. 8 00:00:26,930 --> 00:00:28,910 And all the operations there, as well. 9 00:00:30,280 --> 00:00:32,920 And we'll need to be able to translate a contact's group 10 00:00:32,920 --> 00:00:34,570 field into a database relationship. 11 00:00:35,920 --> 00:00:36,870 Whoa. 12 00:00:36,870 --> 00:00:38,600 We've got some work to do. 13 00:00:38,600 --> 00:00:39,550 And honestly, 14 00:00:39,550 --> 00:00:43,660 sometimes a project could involve this kind of approach we're taking right now. 15 00:00:43,660 --> 00:00:46,840 But often our data becomes too complex in our code 16 00:00:46,840 --> 00:00:49,730 too verbose to keep going down this path. 17 00:00:49,730 --> 00:00:52,090 I mean, what if we had 50 objects, 18 00:00:52,090 --> 00:00:56,400 each having 5 to 10 fields, and what if there are complex relationships among 19 00:00:56,400 --> 00:00:59,960 those objects that we have to translate to database relationships? 20 00:00:59,960 --> 00:01:01,520 This could be a SQL nightmare. 21 00:01:02,740 --> 00:01:07,710 But this is where Object Relational Mapping tools come to the rescue. 22 00:01:07,710 --> 00:01:12,050 Because so many applications are backed by databases, we need a way to translate 23 00:01:12,050 --> 00:01:15,276 between JAVA objects and the persistent storage of data. 24 00:01:15,276 --> 00:01:19,720 Be it MySQL, SQL Server or post press. 25 00:01:19,720 --> 00:01:23,210 There are several benefits to using an ORM. 26 00:01:23,210 --> 00:01:25,570 We could use POJOs to model data. 27 00:01:25,570 --> 00:01:28,430 We can persist POJOs with little code. 28 00:01:28,430 --> 00:01:33,270 Manage relationships among POJOs and model that relationship in the database. 29 00:01:33,270 --> 00:01:36,750 And we can swap the backend database with another system. 30 00:01:36,750 --> 00:01:41,040 And only update the parts in the ORM that interface with the DB. 31 00:01:42,100 --> 00:01:46,110 And we can do all of these without ever having to change POJOs, 32 00:01:46,110 --> 00:01:49,770 models, views, controllers, and what have you? 33 00:01:50,830 --> 00:01:55,393 In general, here is a look at how a Hibernate application can be represented. 34 00:01:55,393 --> 00:02:00,244 In the application will have our typical code that includes our user interface and 35 00:02:00,244 --> 00:02:02,153 the business logic with POJOs. 36 00:02:02,153 --> 00:02:06,769 Then, we'll hand over those POJOs to Hibernate to let it persist them to 37 00:02:06,769 --> 00:02:07,610 a database. 38 00:02:08,650 --> 00:02:12,429 For the remainder of the course, we'll be using an H2 database, 39 00:02:12,429 --> 00:02:15,343 since SQLite is not fully supported by Hibernate. 40 00:02:15,343 --> 00:02:18,707 It will be our job to write the business logic, along with 41 00:02:18,707 --> 00:02:23,278 invoking the proper Hibernate methods to persist POJOs to our H2 database. 42 00:02:23,278 --> 00:02:26,310 Before we start discussing the specifics of hibernate, 43 00:02:26,310 --> 00:02:30,320 it's worth noting here that Hibernate is not the only ORM out there. 44 00:02:30,320 --> 00:02:34,180 There are a lots, and some of them on much lighter weight frameworks that 45 00:02:34,180 --> 00:02:37,580 are perfectly acceptable to use on reasonably small projects. 46 00:02:39,050 --> 00:02:40,200 Let's break here. 47 00:02:40,200 --> 00:02:42,770 And when you're ready to hit Hibernate, I'll see you in the next stage.