Configuring Giflib for Hibernate3:03 with Chris Ramacciotti
This video begins our configuration of Hibernate for use in Giflib. As a first step, we need to add a few dependencies to our Gradle build file, including the Spring ORM, Apache DBCP, and H2 Database libraries.
Git Command to Sync Your Code to the Start of this Video
git checkout -f s1v4
Using Github With This Course
You can complete this course entirely using code created by you on your local machine. However, if you choose to use the code I've made available to you, you have two options:
- Use the project files linked at the bottom of this page, or
- Use the Github repository I've made available (recommended)
If you choose the recommended option of using the Github repository, it can be found at
To utilize Github with this course, you can download the Github desktop client for your system or use the command line interface provided with Git.
Clone this repository to your machine using the Github desktop client, or using the following command:
git clone firstname.lastname@example.org:treehouse/giflib-hibernate.git
To update your local repository to match a video's starting point, you can use the
git checkout command in combination with the stage and video number. For example, to update your local repository to match the starting point of Stage 5, Video 4, you'd use the following:
git checkout -f s5v4
Notice the use of the -f option. This forces Git to override all local changes, so be aware: this will cause any changes you made to be lost.
So you've scrolled through the gif flip code and dusted off the old Spring hat. 0:00 I think it's time to dig into our app and start making some changes. 0:03 We'll begin by discussing how to configure our Spring app to use Hibernate. 0:07 Here we go. 0:11 The first order of business in our configuration, in this app, 0:12 is to add the necessary dependencies. 0:15 We have four that we're going to add. 0:17 First is a dependency on Spring ORM. 0:19 This allows us to integrate an object-relational mapping library 0:22 seamlessly into our Spring app. 0:25 So I'll add that next. 0:27 We'll need data compile time. 0:30 The group name is org.springframework. 0:32 The ID is spring-orm, and 0:35 the version is 4.2.5.RELEASE. 0:39 Then next will be the ORM implementation we're using, 0:44 which in our course is Hibernate. 0:48 So there again, we'll need it as a compile time dependency, 0:51 org.hibernate is the group name. 0:54 hibernate-core is the ID, 0:56 and we're going to use 5.1.0.Final. 0:59 Great. 1:05 The third is a library called, DBCP from Apache. 1:07 DBCP stands for Database Connection Pooling and allows our app to 1:11 reuse database connection objects, since those objects take some time to construct 1:16 being that they're dependent on establishing a connection to the database. 1:20 So here's the dependency for DBCP. 1:24 We'll need that also at compile time. 1:27 The group name is org.apache.tomcat. 1:29 And the ID is tomcat-dbcp, 1:33 the version number 8.0.32. 1:38 Finally, let's add our database provider which will be H2. 1:44 To remind you, H2 is a nice tool because it allows for 1:49 a range of connectivity options. 1:52 From in memory databases that are created and destroyed, and held entirely in memory 1:54 from the time you run your app to the time you kill your app, to portable single file 1:59 databases that don't require you to start a database server, and finally to full 2:03 server based databases, which do require you to start a database server. 2:08 You've seen the file based mode in Hibernate Basics. 2:13 In this course, we'll experiment with server mode. 2:16 So let's add that dependency now. 2:19 Again, this is a compile time database. 2:22 The group name is com.h2database. 2:24 The ID is h2, and the version is 1.4.191. 2:27 Now, let's pop open the Gradle Tool window and refresh our dependencies, 2:33 to pull down those jars and add them to the class path. 2:38 You'll hit that refresh button there, and at the bottom you should see some 2:42 messages that indicate that dependencies are being resolved and downloaded. 2:46 And with those libraries added, we've wrapped up our Gradle build file. 2:51 Now that said, we still have some work to do in configuring our data source in 2:55 Hibernate integration. 2:59 We will tackle these items next. 3:00
You need to sign up for Treehouse in order to download course files.Sign up