Sie sind auf Seite 1von 3

3/28/14

Integrate JavaFX, Hibernate and PostgreSQL with the MVC Pattern

TODAY 'S HEADLINES |

ARTICLE ARCHIVE |

FORUMS |

TIP BANK

Specialized Dev Zones eBook Library .NET Java C++ Web Dev A rchitecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs

Not having data governance can hurt your business. Download this eBook to learn how to take control now.

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.
by Manoj Debnath Jun 5, 2012 Page 1 of 2

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, datadriven 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.
What You Need

Sign up for e-m ail new sletters from DevX

Enter email address

Java SDK + JavaFX 2 Eclipse IDE Hibernate 4.x


Jelastic Updates Java/PHP PaaS With Git, SVN AutoDeploy, More Getting Started w ith Apache HBase Approaches to Indexing Multiple Logs File Types in Solr and Setting up a MultiNode, Multi-Core Solr Cloud

PostgreSQL Database PostgreSQL JDBC Driver


Coding with JRebel: Java Forever Changed Download Now

To follow the demo in this article, simply: 1. 2. 3. 4. 5. Install the Java SDK+JavaFX2 SDK Unpack the Eclipse IDE Install the PostgreSQL DB Unpack Hibernate 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.

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
c f g . s e t P r o p e r t y ( " h i b e r n a t e . c o n n e c t i o n . u r l " , " j d b c : p o s t g r e s q l : / / 1 2 7 . 0 . 0 . 1 : 5 4 3 2 / t e s t d b " ) ;

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.
c f g . s e t P r o p e r t y ( " h i b e r n a t e . h b m 2 d d l . a u t o " ," u p d a t e " ) ;

Also keep in mind the u p d a t evalue. You may also put c r e a t ein place of u p d a t e . This would recreate the table every time the application runs, deleting all stored information. So use c r e a t eor u p d a t eappropriately.
c f g . s e t P r o p e r t y ( " h i b e r n a t e . s h o w _ s q l " ," t r u e " ) ;

Alternatively, you may set the above property as f a l s e . The table created in PostgreSQL is as follows:
C R E A T ET A B L Ec o n t a c t s ( c o n t a c t i di n t e g e rN O TN U L L ,

www.devx.com/Java/Article/48193

1/3

3/28/14

Integrate JavaFX, Hibernate and PostgreSQL with the MVC Pattern


e m a i lc h a r a c t e rv a r y i n g ( 2 5 5 ) , f i r s t n a m ec h a r a c t e rv a r y i n g ( 2 5 5 ) , l a s t n a m ec h a r a c t e rv a r y i n g ( 2 5 5 ) , p h o n ec h a r a c t e rv a r y i n g ( 2 5 5 ) , C O N S T R A I N Tc o n t a c t s _ p k e yP R I M A R YK E Y( c o n t a c t i d) ) W I T H(O I D S = F A L S E) ; A L T E RT A B L Ec o n t a c t sO W N E RT Op o s t g r e s ;

Next Page

1 2

Next Page

2 Comments (click to add your com m ent) By umair October 18 2013 00:52 AM PDT Dear Manoj, Thankyou very much for this easy to understand and effective tutorial. With an ORM architecture like you explained (seems session per click) if we develop a Java FX application with say 200+ clients, would it work or should we go for EJB approach. Thanks again for this self explanatory example. Umair
Reply to this comment

By Sumudu June 29 2013 11:55 AM PDT This is very very important one thank you very very much
Reply to this comment

Comment and Contribute

Your name/nickname Your email WebSite Subject

(Maximum characters: 1200). You have 1200 characters left.

Ketik teks

Submit Your Comment

www.devx.com/Java/Article/48193

2/3

3/28/14

Integrate JavaFX, Hibernate and PostgreSQL with the MVC Pattern

Sitemap

Property of Quinstreet Enterprise. Terms of Service | Licensing & Reprints | About Us | Privacy Policy | Advertise Copyright 2014 QuinStreet Inc. All Rights Reserved.

www.devx.com/Java/Article/48193

3/3

Das könnte Ihnen auch gefallen