Using object-relational mapping frameworks

In a relational database, data is represented as tables. In a Java program, data is represented as objects. For example, if you have data related to customers, you can store this data in a customers table. Similarly, you can store this data in objects which are instances of the Customer class. Object-relational mapping frameworks allow you to convert the data between these two systems.

We already learned how to fetch data via JDBC and the ResultSet interface in the previous chapter. You could take an instance of this interface, iterate over the rows, and manually set the fields of a Java class such as Customer. When you do so, you are doing the job of an ORM framework. Why reinvent the wheel? The Java ecosystem offers several options to fix the object-relational impedance mismatch. In the following sections, we'll examine three of the most popular alternatives to solve this impedance mismatch.

The Object Oriented paradigm is based on software engineering principles, while the Relational paradigm is based on mathematical principles. The object-relational impedance mismatch refers to the incompatibility between these two paradigms.

The examples developed in the following sections use the H2 database instance we initialized during the introduction to JDBC in the previous chapter. Make sure that the H2 server is running and that the messages table exists (see the packt.vaadin.datacentric.chapter05.jdbc.DatabaseInitialization class for details). You can use any other database if you want. If so, make sure your database server is running, create the messages table, and configure your application to point to your new database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset