RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Integrate JavaFX, Hibernate and PostgreSQL with the MVC Pattern

This JavaFX tutorial demonstrates how to integrate JavaFX, Hibernate and PostgreSQL using the MVC pattern -- complete with a sample application that features visual data navigation.


JavaFX provides a rich set of UI controls, which simplify the development of visually immersive front ends for database-driven applications. When combined with the PostgreSQL database and the Hibernate ORM tool, JavaFX can handle the presentation layer for large-scale, data-driven business applications (JavaFX PostgreSQL) as well as robust desktop applications (JavaFX Hibernate).

In this article, I demonstrate how to integrate JavaFX, Hibernate and PostgreSQL using the MVC pattern and present a sample CRUD application with a data-navigation feature.

To follow the demo in this article, simply:

  1. Install the Java SDK+JavaFX2 SDK
  2. Unpack the Eclipse IDE
  3. Install the PostgreSQL DB
  4. Unpack Hibernate
  5. Save the PostgreSQL JDBC driver

JavaFX / Hibernate / PostgreSQL Project Setup

From the File menu in Eclipse, choose Java Project. It is better to set up User Library of all JAR files required in the project. This is not a necessary procedure but it will come in quite handy for future reference. Let's make an individual library for the Hibernate JavaFX PostgreSQL driver and include it in our project, as shown in Figure 1.

JavaFX Hibernate PostgreSQL
Figure 1. Project Library: Make a library for the Hibernate JavaFX PostgreSQL driver.

PostgreSQL Table Structure

You don't need to worry about the structure of the sample table, Contact. It will be created automatically when the application runs. However, if you want to create the table separately, you can but keep in mind the following comment for the code snippets in the rest of the article


In this case, testdb is the table space. If you opt for creating your table through SQL or through pgAdmin III, either give the name of tablespace as testdb or change the appropriate portion of code in the HiberateUtil.java file.

cfg.setProperty("hibernate.hbm2ddl.auto", "update");

Also keep in mind the update value. You may also put create in place of update. This would recreate the table every time the application runs, deleting all stored information. So use create or update appropriately.

cfg.setProperty("hibernate.show_sql", "true");

Alternatively, you may set the above property as false.

The table created in PostgreSQL is as follows:

  contactid integer NOT NULL,
  email character varying(255),
  firstname character varying(255),
  lastname character varying(255),
  phone character varying(255),
  CONSTRAINT contacts_pkey PRIMARY KEY (contactid )
ALTER TABLE contacts OWNER TO postgres;

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date