Home > Articles > Programming > Ruby

Get Started Using Spring MVC and Hibernate for Your Java EE Applications

  • Print
  • + Share This
Programming expert Jesse Smith shows the easy way to get started with the popular Spring MVC framework with Hibernate. Learn how to build a simple application with a registration page.
Like this article? We recommend


This article shows how to use Spring MVC with a popular object relational mapping (ORM) framework called Hibernate. ORM is becoming the most popular way to manage a Java application's persistence layer. An ORM framework maps your database tables to objects in the application with the same name, making the application much easier to construct and maintain. In short, ORM decouples your business-logic layer from your database. With ORM, you use the framework's SQL on your domain model objects—not on the actual database tables. With this type of development, you can change your application's database (for example, from Oracle to SQL Server) without making code changes to your queries, saving a good amount of time.

The application is a simple registration page. Many applications have this page, so you can build and expand it into a full-blown application with all the legwork out of the way.

Setting Up the Database

To get started, choose a persistence store. Hibernate will work with almost any type of database; for this article, I'm using MySQL. I haven't used MySQL for awhile, and I must admit that I'm impressed by the improvements since I last used it.

Our first task is to create a new schema (database):

  1. Using the client workbench, click Create a New EER Model. You'll get the existing default model page for the default mydb schema. By creating or modifying your model first, you're using the "data first" approach to building your ORM application.
  2. Click the plus (+) icon on the far right of the screen to add a new model for what will become a database schema.
  3. Give the model a name that fits your application, and save your changes.

Now you can begin working with your new database schema. Any changes you make to the model can be synchronized with the schema by selecting Database > Query Database from the top menu bar of the editor. But we don't need to add any tables to our model; as you'll see later in this article, Hibernate will do this for us automatically.

Creating the Web Project

Now that the table and database are set up, it's time to create the Spring MVC project. I'm using Eclipse for this example, but any project management tool will work.

  1. Because Eclipse doesn't come with the Spring JAR files, download them from the Spring Community Downloads page and add them to your project.
  2. Download the Hibernate JAR files.
  3. Using Eclipse, create a dynamic web project.
  4. Once the project has been created, add the Spring JAR files (from the Spring framework's dist folder) to this directory in your project:
    An easy way to do this is to drag-and-drop the files from the framework folder onto the web project's lib folder.
  5. Do the same thing for Hibernate by copying the files from the Hibernate framework's lib\required folder to the project's lib directory.
  6. You'll need some additional JAR files to make everything work:
  • + Share This
  • 🔖 Save To Your Account