1 00:00:00,000 --> 00:00:05,009 [MUSIC] 2 00:00:05,009 --> 00:00:07,160 So we've chosen Hibernate as your ORM, 3 00:00:07,160 --> 00:00:12,260 and now it's time to get a grasp of the main components we'll be interacting with. 4 00:00:12,260 --> 00:00:13,630 Check it out. 5 00:00:13,630 --> 00:00:17,470 We've already seen this basic graphic of a Hibernate application. 6 00:00:17,470 --> 00:00:21,870 If we zoom into the Hibernate component, we see some important pieces revealed. 7 00:00:21,870 --> 00:00:24,090 First is the session factory. 8 00:00:24,090 --> 00:00:27,940 In Hibernate, a session factory is a fairly heavy weight object 9 00:00:27,940 --> 00:00:32,890 that contains the relationships between the application and a database. 10 00:00:32,890 --> 00:00:35,990 There is usually just one of these per application. 11 00:00:35,990 --> 00:00:40,515 It encapsulates all the objects related to mapping pojos to database tables and 12 00:00:40,515 --> 00:00:41,360 columns. 13 00:00:41,360 --> 00:00:43,720 Which is contained in the metadata sources object. 14 00:00:45,030 --> 00:00:47,770 A session represents an interaction with the database 15 00:00:47,770 --> 00:00:49,680 in which a live connection is established. 16 00:00:50,690 --> 00:00:55,140 We'll see that before performing any data operations we'll open a session. 17 00:00:55,140 --> 00:00:59,770 And when we're done interacting with the data we'll immediately close the session. 18 00:00:59,770 --> 00:01:02,630 These objects are lightweight and therefore, are created as needed. 19 00:01:03,700 --> 00:01:08,120 A transaction represents a unit of work that must be performed on the database, 20 00:01:08,120 --> 00:01:10,380 which might in compass several queries. 21 00:01:10,380 --> 00:01:14,440 For example, a database transaction performing a bank account transfer 22 00:01:14,440 --> 00:01:19,550 might involve deducting a hundred dollars from one account and adding it to another. 23 00:01:19,550 --> 00:01:22,480 If adding the hundred dollars to the second account fails, 24 00:01:22,480 --> 00:01:25,110 we want to undo the initial deduction. 25 00:01:25,110 --> 00:01:27,360 Otherwise the hundred dollars vanishes. 26 00:01:28,700 --> 00:01:32,880 In a transaction we begin the work, perform all the queries, and 27 00:01:32,880 --> 00:01:37,620 if they succeed, we commit the transaction, which finalizes all queries. 28 00:01:37,620 --> 00:01:42,670 If any part fails, we roll back the transaction which will reverse each query. 29 00:01:42,670 --> 00:01:44,210 Pretty powerful stuff. 30 00:01:44,210 --> 00:01:46,060 And of course, Hibernate supports this. 31 00:01:47,170 --> 00:01:52,400 Finally, a criteria allows us to query the database using its mapped pojo class. 32 00:01:52,400 --> 00:01:55,850 And add restrictions to further filter those results, 33 00:01:55,850 --> 00:02:02,440 using methods that translate to the SQL Like or > or = operators. 34 00:02:02,440 --> 00:02:06,990 At their most basic level these restrictions translate to simple or 35 00:02:06,990 --> 00:02:08,990 compound where clauses. 36 00:02:10,320 --> 00:02:13,480 All right, now that you've seen some of the main components of Hibernate. 37 00:02:13,480 --> 00:02:14,752 Let's dive in. 38 00:02:14,752 --> 00:02:16,460 Meet me in the next video to start coding.